我正在尝试在 Zend Framework(版本 1.11.11)中的 routes.ini 文件中设置路由,这将允许匹配以下 url:
my.domain.com/shop/add/123
到ShopController
和addAction
。但是,由于某种原因,我的操作无法识别参数(末尾的数字)。我得到的 PHP 错误是
Warning: Missing argument 1 for ShopController::addAction(), called in...
我知道我可以在引导程序中使用 PHP 代码进行设置,但我想了解如何在 .ini 文件中进行此类设置,我很难找到任何解释这一点的资源。我还应该指出,我在我的项目中使用了模块。我使用这里和网上找到的各种片段想出了以下内容:
应用程序/配置/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+
引导程序.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 中路由的基本知识。