有人能向我解釋如何解決這個錯誤「沒有對象管理器設置」沒有對象管理器設置ZF2字段集
這裏是字段集:
namespace Trunk\Form;
use Trunk\Entity\Category;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class CategoryFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct($objectManager)
{
parent::__construct('category');
$this->setHydrator(new DoctrineHydrator($objectManager, 'Trunk\Entity\Category'));
$this->add(array(
'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
'name' => 'title',
'object_manager' => $objectManager,
'target_class' => 'Trunk\Entity\Category',
'property' => 'title',
'is_method' => false,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array('parentid' => 0),
'orderBy' => array('title' => 'ASC'),
),
)
));
}
}
以下是錯誤消息:
F:\ XAMPP \ htdocs中\ travelltheworld \供應商\主義\主義模塊的\ src \ DoctrineModule \表格\元素\ Proxy.php:535
無對象管理器已設置
我已將工廠中的實體管理器注入到名爲ProductForm的表單中。在該表單中,我有一個名爲ProductFieldset的base fieldset,在ProductFieldset中插入了CategoryFieldset,我需要從數據庫中選擇類別並將它們顯示在選擇框中。
如果您需要更多的代碼或解釋,請問我。
首先,我想對最近的回覆表示歉意,並感謝@Hooli。你的回答是正確的!我在表單和字段集中使用了Initializers而不是構造函數。我使用INTERFACE ObjectManagerAwareInterface而不是特質。我遵循https://github.com/doctrine/DoctrineModule/issues/175中的解釋 – Sezgin