2013-05-20 146 views
0

我必須升級其他人使用Symphony 1.4開發的應用程序。Symfony 1.4的路由問題

裏面我action.class.php有兩種不同的功能:

public function executeCreateTask(sfWebRequest $request) {...} 
public function executeCreateEvent(sfWebRequest $request) {...} 

和我的routing.yml裏我有2種途徑:

evaluation_task_create: 
url:  /evaluation/:id/task/create 
class: sfDoctrineRoute 
options: { model: Evaluation, type: object } 
param: { module: evaluation, action: createTask, sf_format: html } 
requirements: { sf_method: post } 

evaluation_event_create: 
url:  /evaluation/:evaluation_id/event/create 
class: sfDoctrineRoute 
options: { model: CustomEvent, type: object } 
param: { module: evaluation, action: createEvent, sf_format: html } 
requirements: { sf_method: post } 

網址 http://www.mysite/evaluation/21/task/create完美工作(創建一個新的任務)

網址 http://www.mysite/evaluation/21/event/create返回404錯誤。

任何想法,爲什麼我有這個路由問題?

+0

你在做GET或POST請求嗎?請注意,您的第二條路線包含'要求:{sf_method:post}'。如果這不是問題,那麼你的'debug'設置設置爲true?什麼是您收到的extact錯誤消息? – meijuh

+0

該請求由具有POST方法的表單觸發。我沒有收到任何錯誤,它只是跳轉到Symfony的404錯誤頁面。 –

+0

這個錯誤頁面說什麼?你是否得到了一個sfError404Exception',其中包含一個類似'Empty module and/or action after parsing the URL「/ evaluation/21/event/create」(/)「的消息。 – meijuh

回答

2

您需要能夠進一步調試,因爲您沒有收到sfError404Exception。你在你的ApplicationConfiguration中設置debug爲true嗎?您可以在您的webdispatcher中爲您的dev環境執行此操作。

$configuration = ProjectConfiguration::getApplicationConfiguration(
    'backend', 
    'dev', 
    true 
); 

而在你的應用程序的settings.yml

dev: 
    error_reporting: <?php echo (E_ALL | E_STRICT)."\n" ?> 
    web_debug: true 

而在你的應用程序的factories.yml確保您已設置

dev: 
    logger: 
    param: 
     loggers: 
     sf_web_debug: 
      param: 
      xdebug_logging: true 
+0

我收到一個sfError404Exception:「解析URL後的空模塊和/或動作」/ evaluation/event/create「(/)」。 –

+0

所以你設法解決你的問題?你有沒有注意到'/ evaluation/event/create'不包含':id'?另外確保在生產環境中禁用調試。 – meijuh

0

在你evaluation模塊的createEvent動作,你有可能是一些像

$this->evalution = $this->getRoute()->getObject(); 

要從路徑中獲取正確的對象,您需要使用:id變量作爲對象的id並指定正確的模型Evaluation而不是CustomEvent。因此,請嘗試將evaluation_event_create路線更改爲:

evaluation_event_create: 
    url:  /evaluation/:id/event/create 
    class: sfDoctrineRoute 
    options: { model: Evaluation, type: object } 
    param: { module: evaluation, action: createEvent, sf_format: html } 
    requirements: { sf_method: post } 

並清除緩存。

+0

也許他想使用'CustomEvent'?我想默認情況下,url中的所有變量都會傳遞給從數據庫中檢索這樣一個對象的方法。 – meijuh