我試圖讓URL路由工作,以便我可以通過AJAX調用控制器的功能。 AJAX調用形成爲「ajax/{控制器中的函數名稱}/{傳遞給函數的ID}」。URL路由不起作用
我已經添加下面我routes.yml:
Director:
rules:
'ajax': 'TakeActionPage_Controller'
在我TakeActionPage_Controller,我有:
private static $url_handlers = array(
'electoratesfrompostcode/$ID' => 'electoratesfrompostcode',
);
public function electoratesfrompostcode(SS_HTTPRequest $request)
{
$id = (int)$request->param('ID');
return $this->getElectoratesFromPostcode($id);
}
這是行不通的。當我添加?debug_request=1
到TakeActionPage的URL,我得到:
Debug (line 250 of RequestHandler.php): Testing 'electoratesfrompostcode/$ID' with '' on TakeActionPage_Controller
Debug (line 250 of RequestHandler.php): Testing '$Action//$ID/$OtherID' with '' on TakeActionPage_Controller
Debug (line 258 of RequestHandler.php): Rule '$Action//$ID/$OtherID' matched to action 'handleAction' on TakeActionPage_Controller. Latest request params: array ('Action' => NULL, 'ID' => NULL, 'OtherID' => NULL,)
Debug (line 184 of RequestHandler.php): Action not set; using default action method name 'index'
我真的不知道做這些調試信息的內容。任何想法如何得到這個工作?
debug_request的實際URL是什麼?你還粘貼了上面所有的代碼,因爲它說你在你的頁面控制器''$ Action // $ ID/$ OtherID''中有這個規則,但它不在你的代碼中? – colymba