Php Symfony:如何在executeNew()和executeCreate()之间传递变量?
在symfony/doctor下,我想将URL参数中包含的值设置为表单Php Symfony:如何在executeNew()和executeCreate()之间传递变量?,php,symfony1,doctrine,Php,Symfony1,Doctrine,在symfony/doctor下,我想将URL参数中包含的值设置为表单 offer/registration/new?offer_id=23 public function executeNew(sfWebRequest $request) { // echo $request->gerParameter('offer_id'); // echoes 23 $this->form = $this->configuration->getF
offer/registration/new?offer_id=23
public function executeNew(sfWebRequest $request)
{
// echo $request->gerParameter('offer_id');
// echoes 23
$this->form = $this->configuration->getForm();
$this->offer_registration = $this->form->getObject();
}
public function executeCreate(sfWebRequest $request)
{
// echo $request->gerParameter('offer_id');
// echoes nothing
$offer = new OfferRegistration();
$offer->setOfferId($offer_id);
$this->form = $this->configuration->getForm($offer);
$this->offer_registration = $this->form->getObject();
$this->processForm($request, $this->form);
$this->setTemplate('new');
}
如何在executeNew()和executeCreate()之间传递$offer\u id,以便在表单上设置正确的OfferId?
PS:我知道我正在使用一个管理后端模块单击新链接时,您需要传递一个参数。默认情况下,symfony生成器在创建新对象时不传递任何参数 要修改正在生成的链接,需要修改已创建的模板文件。最好的方法是从缓存文件夹中获取它,并将其复制到/backend/modules/templates文件夹中,然后修改该文件 可以找到有关管理生成器模板系统的更多信息
找到生成“创建新链接”的文件后,您可以修改该链接以添加参数。在我的情况下,我猜是这样的:。我说的对吗?不-模板中没有$request对象。您需要确定要传递给操作的ID。数组中应该有:$offer\u id=>$idVariable--您可以在executeIndex操作中设置变量($this->idVariable=$foo),因为新链接出现在索引中。是的,但我已经可以访问ExecuteView中所需的变量。我不确定我是否理解了这里的所有内容,所以当显示项目列表时,executeIndex会触发。在索引中,它还将显示“创建新链接”。您需要在createNew链接中插入ID。当您单击该链接时,它将触发executeNew。。因此,本质上,直到事实发生之后才有变量。您需要找出如何从索引中获取该变量。