Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:16:15+00:00 2026-06-10T12:16:15+00:00

I need to change page title from default Error when handling errors like 404.

  • 0

I need to change page title from default “Error” when handling errors like 404. So I need to put my the title in the variable $title_for_layout for my Layout. I tried to create custom error handling function by changing configuration in app/Config/core.php and setting the page title as in controllers

Configure::write('Error.handler', function($code, $description, $file = null, $line = null, $context = null) {
     $this->set('title_for_layout', 'Vyskytla sa chyba');
});

As I expected, I got a PHP error (line 59 is the second line in the code sample)

Fatal error: Using $this when not in object context in /var/www/web/app/Config/core.php on line 59

So how I can set the title for my default.ctp layout?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:16:16+00:00Added an answer on June 10, 2026 at 12:16 pm

    In CakePHP 2.0, you can try the following code to achieve the same you needed.

    Try this:

    /app/Config/core.php

    Exception render need to set as an AppExceptionRender. Example:

    Configure::write('Exception', array(
            'handler' => 'ErrorHandler::handleException',
            'renderer' => 'AppExceptionRenderer',
            'log' => true
    ));
    

    /app/Controller/ErrorsController.php

    class ErrorsController extends AppController {
        public $name = 'Errors';
    
        public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('error404');
        }
    
        public function error404() {
            //$this->layout = 'default';
                $this->set('title_for_layout', 'Vyskytla sa chyba'); 
        }
    }
    

    /app/Lib/Error/AppExceptionRenderer.php

    App::uses('ExceptionRenderer', 'Error');
    
    class AppExceptionRenderer extends ExceptionRenderer {
    
        public function notFound($error) {
            $this->controller->redirect(array('controller' => 'errors', 'action' => 'error404'));
        }
    }
    

    /app/View/Errors/error404.ctp

    <div class="inner404">
        <h2>404 Error - Page Not Found</h2>
    </div>
    

    Insert it where you need: throw new NotFoundException();

    Ref: CakePHP 2.0 – How to make custom error pages?

    For < CakePHP 2.x:

    If you create a custome error page view in app/views/errors then in a
    php section on that error view page you can use:

    $this->setLayout("Title for the error page here");
    

    Then when you see the error page, it will have your title. Again, that
    is if you set a custom error page.

    Here is another way to do the same you needed.

    // Create an error.php file in your /app folder with the following code:
    
    <?php
    class AppError extends ErrorHandler {
        function error404($params) {
                $this->controller->layout = "error";
                $this->set('title_for_layout', 'Vyskytla sa chyba');
                parent::error404($params);
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to dynamically change the page title in Sitefinity from a
need to change the URL as per Title of the page.I have a URL
Sometimes I need to set some string values from code, for example: Page.Title =
I need to change Font Size of Page Items Help Text in Oracle Apex.
I need that on every page change or on some elemetents (a, input[button, submit],
I need to redirect users to the Change Password page if their password has
I need to change a bunch of different words on a page using jQuery.
I need change background of all text that have two spaces from the start
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
I need to read some content from a html page. I've tested simple_html_dom ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.