Php 在Zend Framework 2中获取参数

Php 在Zend Framework 2中获取参数,php,zend-framework,Php,Zend Framework,我试图用Zend Framework 2获得一个特定的参数。比如说, // set the form to be used in the update templates view $form = new EmailTemplateForm(); // gets the form method request (usually post) $request = $this->getRequest(); // check to see if the req

我试图用Zend Framework 2获得一个特定的参数。比如说,

// set the form to be used in the update templates view
    $form = new EmailTemplateForm();

    // gets the form method request (usually post)
    $request = $this->getRequest();

    // check to see if the request was a POST form request
    if ($request->isPost()) {
        // good to go
        // filter the form values now
        $email = new EmailTemplates();

        $form->setInputFilter($email->getInputFilter());

        // set the form data to hold all the values supplied by the form
        // via $request->getPost()
        $form->setData($request->getPost());

        // now we will see if the form is valid
        // we check if it is valid by the email form class we created
        if ($form->isValid()) {
            // it is valid
            // pass the form to data to the filter class via exchangeArray()
            $email->exchangeArray($form->getData());

            $tpl_id = !empty($this->getRequest()->getParam('id'))
            ? $this->getRequest()->getParam('id') : null;

            if ($this->getEmailTemplatesService()->modifyEmailTemplate($email, $tpl_id) === true) {
                // the updated email template was inserted into the database successfully
                // redirect to email template view
                return $this->redirect()->toUrl('/admin/email-template');
            } else {
                // error occured..
                // the error is logged automatically
                // redirect to email template view
                return $this->redirect()->toUrl('/admin/email-template/' . $tpl_id);
            }
        }
    } 
$this->getRequest()->getParam('id')是否会从页面url返回id号?我已将路线设置为以下格式:

'route'    => '/admin[/][:action][/:id]',
因此,如果表单已提交(通过POST),且相应的url为/admin/edit template/3,$this->getRequest()->getParam('id')是否包含3


谢谢

如果您想从post获取参数,可能最好使用:
$this->params()->fromPost('param_name')

如果您想要从路线:
$this->params()->fromRoute('id')


您可以使用“id”输入名称创建,也可以使用路由中的id。

是的,如果post url具有相同的参数,它将起作用,为什么您要询问而不是尝试?现在无法测试它。谢谢你的帮助:)