PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] Is it possible to use AppController on error pages? (Cakephp 3.1)

 January 17, 2022     cakephp, cakephp-3.0, cakephp-3.1     No comments   

Issue

I am trying to render error templates (eg error400.ctp) but with the default layout (site header and footer) which relies on components and variables set in AppController. How do I tell Cake to use AppController when rendering error pages?

I have already tried making an ErrorController which extends AppController, but it breaks for missing actions.


Solution

Here's my working ErrorController in case anyone comes looking for it:

<?php
namespace App\Controller;

use App\Controller\AppController;
use Cake\Event\Event;

class ErrorController extends AppController
{

    public function beforeRender(Event $event)
    {
        parent::beforeRender($event);
        $this->viewBuilder()->templatePath('Error');
    }

}

There was a bug in one of my Components being loaded in AppController. When ErrorController extends AppController and one tries to access an invalid action in a controller it creates two instances of AppController and in my case a duplicate declaration of class error was thrown because of a bug in my component. This error caused some kind of loop causing the error page not to render.



Answered By - Test Testington
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing