gpt4 book ai didi

php - 在 Zend Framework 中使用 URL 段作为操作方法参数

转载 作者:行者123 更新时间:2023-12-03 00:53:51 25 4
gpt4 key购买 nike

在 Kohana/CodeIgniter 中,我可以拥有以下形式的 URL:

http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ...

然后读取我的 Controller 中的参数如下:

class MyController 
{
public function method_name($param_A, $param_B, $param_C ...)
{
// ... code
}
}

如何在 Zend 框架中实现这一目标?

最佳答案

看一下 Zend_Controller_Router 类:

http://framework.zend.com/manual/en/zend.controller.router.html

这些将允许您定义一个 Zend_Controller_Router_Route,它以您需要的方式映射到您的 URL。

索引 Controller 的索引操作有 4 个静态参数的示例是:

$router = new Zend_Controller_Router_Rewrite();

$router->addRoute(
'index',
new Zend_Controller_Router_Route('index/index/:param1/:param2/:param3/:param4', array('controller' => 'index', 'action' => 'index'))
);

$frontController->setRouter($router);

在定义前端 Controller 后,它将添加到您的 Bootstrap 中。

一旦采取行动,您就可以使用:

$this->_request->getParam('param1');

在操作方法中访问值。

安德鲁

关于php - 在 Zend Framework 中使用 URL 段作为操作方法参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/161443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com