Chv*_*off 1 php zend-framework zend-form
我正在使用“ Zend表单”。我应该怎么做才能在FORM标签中获得正确的“操作”参数?
例如,indexAction中的SearchController中使用的Form_Search形式。我应该在哪里以及如何设置action参数以使其形成“ / my / app / directory / search / index”?
更新:“ action”参数应该与表单相同(如果未设置)。我只需要FORM中的参数来简化JS编码。
您可以使用Zend_Form的setAction方法,例如:
$yourForm->setAction('/my/app/directory/search/index');
Run Code Online (Sandbox Code Playgroud)
希望这是您想要的。
编辑:您可以使用$ this-> getRequest()方法在操作中检索返回有关请求的许多信息,该方法返回的实例Zend_Controller_Request_Http。例如,如果要获取basePath以及BaseUrl和QueryString之间的所有内容,则可以执行以下操作:
$infoPath = $this->getRequest()->getPathInfo();
$basePath = $this->getRequest()->getBaseUrl();
$yourForm->setAction($basePath . $infoPath);
Run Code Online (Sandbox Code Playgroud)
Zend_Controller_Request_Http 还有其他可能对您有用的方法。