我想在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中路由的基本知識。