【发布时间】:2014-06-05 10:23:30
【问题描述】:
我正在尝试通过表单工厂访问路线和发布。路由或帖子包含一个 ID,我需要将其注入到我的表单中,以便我可以构建一个 select 语句。
目前我正在使用
通过控制器注入表单$this->MyForm->get('elementName')->setOptions(array('value_options' =>$myArrayOfOptions));
我的目标是将业务逻辑排除在控制器之外,因此我热衷于使用 formFactory,但我确实需要访问帖子或路由中的 ID 来实现这一点。
我的表单工厂如下所示:
<?php
namespace MyModule\Form;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use AdminLottery\InputFilter\MyFilter;
use AdminLottery\Service\MyService;
class MyFormFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(
ServiceLocatorInterface $serviceLocator
)
{
//$serviceLocator is FormElementManager
$realSL = $serviceLocator->getServiceLocator();
//*** I NEED TO ACCESS THE ID / POST HERE TO SEND TO MY FORM
return new MyForm(
$realSL->get('Doctrine\ORM\EntityManager'),
$realSL->get('InputFilterManager')->get(MyFilter::class),
$realSL,
$realSL->get(MyService::class)
);
}
}
有什么想法吗??
【问题讨论】:
标签: zend-framework2