【问题标题】:ZF2 Form Collections Zend\Form\FormElementManager::get was unable to fetch or create an instance forZF2 表单集合 Zend\Form\FormElementManager::get 无法获取或创建实例
【发布时间】:2014-11-09 08:30:09
【问题描述】:

我遇到了一个非常奇怪的问题。使用我的开发环境(在 Ubuntu Guest 上共享的 Windows 主机)时,以下代码可以正常工作。但是,当在 linux 服务器上或者即使我将文件复制到 Ubuntu 来宾但本机方向(不从主机共享)时,代码也会失败。我收到的错误是:

Zend\Form\FormElementManager::get was unable to fetch or create an instance for RA\Restriction\Form\ValueFieldset

所以问题是它永远无法找到文件。堆栈跟踪终止于

/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('RA...', true)

这是我的表单文件的样子

namespace RA\Restriction\Form;

use Zend\Form\Form;
use Zend\Form\Element;
use Zend\InputFilter\InputFilter;

class RestrictionValueForm extends Form
{
    public function __construct($name = null)
    {
    // we want to ignore the name passed
    parent::__construct('attribute');
    $this->setAttribute('method', 'post')
        ->setInputFilter(new InputFilter());;
    $this->add(array(
        'name' => 'restriction_id',
        'attributes' => array(
            'type'  => 'hidden',
            'id' => 'restriction_id',
        ),
    ));
    $this->add(array(
        'type' => 'collection',
        'name' => 'value_name',
        'options' => array(
            'count' => 2,
            'should_create_template' => true,
            'template_placeholder' => '__placeholder__',
            'label' => '',
            'target_element' => array(
                'type' => 'RA\Restriction\Form\ValueFieldset',
            ),
        ),
    ));

    $this->add(array(
        'name' => 'submit',
        'attributes' => array(
            'type'  => 'submit',
            'class' => 'btn btn-primary mar-right5',
            'value' => 'Save',
            'id' => 'submitbutton',
        ),
    ));
    $this->add(array(
        'name' => 'cancel',
        'attributes' => array(
            'type'  => 'button',
            'class' => 'btn',
            'value' => 'Cancel',
            'id' => 'cancel',
        ),
    ));
    }
}

我整天都在研究这个问题,但未能提出解决方案,我什至构建了几个额外的环境并确保配置相同。任何建议将不胜感激。

【问题讨论】:

  • 文件在哪里?
  • 在路径/module/RA/src/RA/Restriction/Form/ValueFieldset.php
  • 我终于能够解决问题了。似乎在某些环境中,它不喜欢该字段集位于子目录中。我能够将我的字段集移动到 /RA/src/RA/Form/ValueFieldset 并且现在一切都很开心。

标签: php zend-framework2 zend-form zend-form-element


【解决方案1】:

就我而言,问题在于区分大小写。 Windows 在目录结构和一般情况下不区分大小写,但 linux 区分大小写。

【讨论】:

  • 这也是我的问题。
【解决方案2】:

我终于能够解决这个问题。似乎在某些环境中,它不喜欢该字段集位于子目录中。我能够将我的字段集移动到 /RA/src/RA/Form/ValueFieldset ,现在一切都很开心。

【讨论】:

    猜你喜欢
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2023-03-20
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    相关资源
    最近更新 更多