我还是Zend Framework的新手,对一些概念感到困惑。
我已经构建了一个POST表单,并在表单末尾的URL中附加了一个唯一的 Id 。我现在想在提交表单时收集该ID,但我不知道该怎么做
我会告诉你我想要做的事:
以下是将表单从我的控制器页面呈现到视图的功能。您将注意到我已经为表单输入了一个带有ID
的返回操作地址 $action = "{$this->view->baseUrl()}/sample-manager/process-price/{$sampleId}";
$this->view->Form = $model= $this->_model->createForm($action);
接收帖子的功能如下。但是,我想收集应该返回的返回值的ID,但我不知道在哪里找到它或如何附加它。
public function processPriceAction()
{
$this->requirePost();
if($this->_model->processTieredPriceForm($this->view->form, $this->getRequest()->getPost()))
{
$this->_helper->FlashMessenger('Changes saved');
return $this->_redirect("/product-ecommerce/{$this->_model->getProduct()->id}");
}
else
{
return $this->render('index');
}
}
总之,当回复帖子时,返回地址是否附带Zend Framework中的帖子?
答案 0 :(得分:0)
答案取决于您的路由设置方式。如果您使用默认设置,则在操作名称之后,默认路由允许其他数据的键/值对。所以,你可能会对这样的URL有更多好运:
{$this->view->baseUrl()}/sample-manager/process-price/id/{$sampleId}
这会将您的sampleId放在名为'id'的命名参数中,您可以使用$this->_getParam('id')
在控制器操作中访问该参数。
答案 1 :(得分:0)
你能不能将id提供给表单的构造并将其分配给隐藏元素?例如,在您的控制器中:
$action = "{$this->view->baseUrl()}/sample-manager/process-price";
$this->view->Form = $model= $this->_model->createForm($action, $sampleId);
在您的表单模型中(此处未提供最佳猜测):
$sampleId = new Zend_Form_Element_Hidden('sampleId');
$sampleId->setValue($sampleId);
$form->addElement($sampleId);
然后在发布表单后,您应该能够以标准方式获取控制器中的示例ID:
$sampleId = $this->getParam('sampleId');