2010-11-13 31 views
1

我將Symfony 1.4與Propel一起用作ORM。我爲我的前端頁面創建了一個登錄系統,用戶可以在其中登錄和編輯賬戶詳細信息。頁面設置爲Permission =「user」和Group =「user」。但是,在用戶不屬於這個組的情況下登錄時,重定向到symfonys默認頁面(顯示用戶沒有憑據來查看此頁面)。 可以自定義這些頁面並設置我們自己的自定義消息。我們如何設置自定義錯誤頁面?在symfony中設置自定義錯誤重定向?

,我已經使用的代碼,

if($this->getContext()->getUser()->hasCredential("user")) 
{ 
    $user_name=$this->getUser()->getGuardUser()->getUsername(); 
    $this->name=$user_name; 
} 
else 
{ 
    $this->forward("userlogin", "error"); 
} 

,但我不知道這是最好的方式..

回答

4

您可以在您的應用程序覆蓋它們更改模板: apps/<appname>/modules/default/templates/error404Success.php

要查看可能的模板列表,請看: lib/vendor/symfony/lib/controller/default/templates/

Now關於憑證。在文件apps/<appname>/config/settings.yml

# ... 

all: 
    # ... 

    .actions: 
    login_module:   sfGuardAuth # Change this to whatewer You want. 
    login_action:   signin  # Change this to whatewer You want. 

    error_404_module:  default  # Change this to whatewer You want. 
    error_404_action:  error404  # Change this to whatewer You want. 

所以,如果你想改變只是模板 - 變化只是模板。但是如果你想要更強大的功能 - 更改settings.yml並編寫自定義代碼。

+0

嘿感謝@petraszd – 2010-11-13 11:17:11

+0

其實這是不工作!我已經在模塊中設置了動作(error404Success.php)並將配置設置爲error_404_module:mymodule和error_404_action:error404。但不工作...它被重定向到默認的.. – 2010-11-13 13:27:29

+0

得到了問題,實際上我正在檢查開發模式,因此它不顯示我的自定義錯誤頁面... ... – 2010-11-17 10:57:22

0

你應該看日誌,看看它爲什麼沒有找到你的404行動,它的尋找等

+0

好吧,我會研究它...在Route文件中完成任何事情嗎? – 2010-11-16 09:21:14

+0

謝謝@Gregoire,你的評論是非常有用的,以得到錯誤... – 2010-11-17 10:58:27

+0

不客氣:) – Gregoire 2010-11-17 15:15:05