Happy Coder
Happy Coder

Reputation: 4682

403 Error page not showing in Symfony

I am using Symfony 1.4 for onr of my project and it is needed to show a custom 403 error page. I have given the following in settings.yml

 .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

I also have the error modules and corresponding error success pages. But it is not showing the custom error pages. Instaed in some cases for ex: 404 it is showing a debug page . 403 page is returned with a default forbidden error message. My action file is like the following:

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)
  {
  }
}

EDIT : Adding settings.yml modifications

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

Upvotes: 1

Views: 1612

Answers (3)

Visavì
Visavì

Reputation: 2333

In your case the settings.yml should be:

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"

For the 500 error page, create a directory error in your app/appname/config directory and put a error.html.php file in it (a complete html page).

About the 404 error page, this page (like the 500 error page) is overwritten in the dev environment with the debug page but it will show correctly in the prod environment.

Upvotes: 1

ivoba
ivoba

Reputation: 5986

you probably need to unsecure the 404 action:
see here: http://symfony-check.org/permalink/customize-the-oops-page-not-found-page

Upvotes: 0

Maerlyn
Maerlyn

Reputation: 34107

That is not the correct way to override the 403 error pages. Use secure_module and secure_action.

Upvotes: 0

Related Questions