2014-03-24 173 views
0

我試圖讓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' 

我真的不知道做這些調試信息的內容。任何想法如何得到這個工作?

+0

debug_request的實際URL是什麼?你還粘貼了上面所有的代碼,因爲它說你在你的頁面控制器''$ Action // $ ID/$ OtherID''中有這個規則,但它不在你的代碼中? – colymba

回答

0

原來我張貼的問題的代碼實際上是工作。我以前有不同的代碼不工作,並且使用?debug_request=1時返回相同的調試信息。然後我將代碼更改爲問題中發佈的內容,並且仍然獲得相同的調試信息,所以我認爲它仍然無法正常工作,但實際上它是。

如果它顯示完全相同的工作代碼和非工作代碼消息,則不太確定調試信息的內容。