403错误页面没有在Symfony中显示

问题描述:

我在我的项目的onr上使用Symfony 1.4,需要显示一个自定义的403错误页面。我在settings.yml中给出以下内容403错误页面没有在Symfony中显示

.actions: 
    error_404_module: errors 
    error_404_action: error404 
    error_500_module: errors 
    error_500_action: error500 
    error_403_module: errors 
    error_403_action: error403 

我也有错误模块和相应的错误成功页面。但它没有显示自定义错误页面。在某些情况下,例如:404显示了一个调试页面。使用默认的禁止错误消息返回403页面。我的操作文件是这样的:

class errorsActions extends sfActions 
{ 
/** 
    * Executes index action 
    * 
    * @param sfRequest $request A request object 
    */ 
    public function executeIndex(sfWebRequest $request) 
    { 
    //$this->forward('default', 'module'); 
    } 

    public function executeError404(sfWebRequest $request) 
    { 
    } 

    public function executeError500(sfWebRequest $request) 
    { 
    } 
    public function executeError403(sfWebRequest $request) 
    { 
    } 
} 

编辑:添加settings.yml中修改

.actions: 
    error_404_module: errors 
    error_404_action: error404 
    error_500_module: errors 
    error_500_action: error500 
    secure_module: errors 
    secure_action: error403 

在你的情况settings.yml中应该是:

all: 
    .actions: 
    # page not found 
    error_404_module:  errors  # module "errors" 
    error_404_action:  error404 # action "executeError404" 

    # 403 credential required 
    secure_module:   errors  # module "errors" 
    secure_action:   error403 # action "executeError403" 

对于500错误页面,创建一个目录error在您的app/appname/config目录中,并放入一个error.html.php文件(完整的html页面)。

关于404错误页面,此页面(如500错误页面)在调试页面的dev环境中被覆盖,但它将在prod环境中正确显示。

+0

提到的安全设置403错误页面......?这对我来说至关重要 – 2012-07-19 06:02:44

+0

它在我的答案! ;) – 2012-07-19 06:09:10

+0

Thanks.done那也,,但不工作 – 2012-07-19 06:57:42

那是不是覆盖403个错误页面的正确方法。使用secure_modulesecure_action

+0

已经完成。但它显示相同的页面 – 2012-07-19 07:31:36

+0

请在你的问题中把你编辑settings.yml的相关部分。它应该工作,所以你没有正确地做。 – Maerlyn 2012-07-19 07:56:03

+0

我现在已经添加了。也关闭了ivoba – 2012-07-19 08:00:21

你可能需要取消保护的404动作:
在这里看到:http://symfony-check.org/permalink/customize-the-oops-page-not-found-page