我想从URL获取2个参数并在操作中使用它们,这是我的代码:
网址:mysite.com/myaction/1/string
myaction:
public function myactionAction($id, $string)
{
$params = $this->_getAllParams();
print_r($params);
}
我是ZF的新手,所以如何获得这两个参数?
解决方法:
您需要在url中编写参数名称,然后通过以下方式获取参数值:
$param1 = $this->getRequest()->getParam('param1');
$param2 = $this->getRequest()->getParam('param2');
网址应如下所示:
http://example.com/mycontroller/myaction/param1/value1/param2/value2
如果要从以下网址获取参数值:
http://example.com/myaction/value1/value2
然后去Zend Route.试试下面的代码:
routes.activate.type = "Zend_Controller_Router_Route"
routes.activate.route = "activate/:param1/:param2"
routes.activate.defaults.module = "core"
routes.activate.defaults.controller = "newsletter"
routes.activate.defaults.action = "activate"