我想在route.ini文件中设置Zend Framework(版本1.11.11)中的路由,这将允许匹配以下url:动作参数路由不工作在Zend框架routes.ini
my.domain.com/shop/add/123
到ShopController
和addAction
。但是,由于某种原因,参数(最后的数字)没有被我的动作所识别。我得到的PHP错误是
Warning: Missing argument 1 for ShopController::addAction(), called in...
我知道我可以在引导使用PHP代码中设置的,但我想知道如何做到这一点的安装类型在一个.ini文件,我很难找到解释这一点的资源。我还应该指出,我在我的项目中使用了模块。我想出了利用这里找到各种片段,并有在线如下:
的application/config/routes.ini:
[routes]
routes.shop.route = "shop/add/:productid/*"
routes.shop.defaults.controller = shop
routes.shop.defaults.action = add
routes.shop.defaults.productid = 0
routes.shop.reqs.productid = \d+
bootstrap.php中:
...
protected function _initRoutes()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'routes');
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig($config, 'routes');
}
...
ShopController .php
<?php
class ShopController extends Egil_Controllers_BaseController
{
public function indexAction()
{
// action body
}
public function addAction($id)
{
echo "the id: ".$id;
}
}
任何建议,为什么这不工作?我有一种感觉,我错过了一些关于通过.ini文件在Zend中路由的基本知识。