php - 如何从 zend 框架 1 中的 url 获取参数?

标签 php zend-framework parameters get

我想从 URL 获取 2 个参数并在我的操作中使用它们,这是我的代码:

网址:mysite.com/myaction/1/string

我的 Action :

public function myactionAction($id, $string)
{

$params = $this->_getAllParams();
        print_r($params);
}

我是 ZF 的新手,我如何获得这 2 个参数?

最佳答案

你需要在 url 中写入参数名称,然后通过以下方式获取你的参数值:

$param1 = $this->getRequest()->getParam('param1');

$param2 = $this->getRequest()->getParam('param2');

URL 应该是这样的:

http://example.com/mycontroller/myaction/param1/value1/param2/value2

如果你想从下面的 url 获取参数值:

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"

关于php - 如何从 zend 框架 1 中的 url 获取参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28023242/

相关文章:

php - 无法在我的 Linux 服务器上触发 Cron 事件

从两个表中选择 PHP

PHP安全系统

php - 通过多次 foreach 循环计算用户积分的有效方法是什么?

php - 使用 Zend 将多个 URL 段放入 1 个变量中

php - 我可以在声明 PHP 类常量时使用 storage_path() 吗?

php - Zend_Db 的 Where 子句未按预期工作

c++ - 具有多个参数的对象数组

c++ - 类似参数包的用法是有线的

ios - 实例成员作为默认参数