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

Friday, January 28, 2022

[FIXED] beforeFilter() not being called?

 January 28, 2022     cakephp, cakephp-1.3, php     No comments   

Issue

I have added a function to check for language parameter to my AppController

function beforeFilter(){
    if(Configure::read('Config.language') == 'ara'){
         $this->layout = 'rtl-layout';
    } else {
        $this->layout = 'ltr-layout';
    }
}

but it doesn't work in my other controllers ?

class ImagesController extends AppController {

    var $name = 'Images';
    var $helpers = array('TinyMCE');

    function beforeFilter(){
        if(!isset($this->params['admin'])) {
            $this->Session->setFlash(__('Access denied.', true));
            $this->redirect(array('controller'=>'users','action'=>'login','admin'=>false));
            exit();
        }    
    }

    function index() {
        $this->Image->recursive = 1;
        $this->set('images', $this->paginate());
    }

}

Please help me, it's driving me nuts.


Solution

I forgot to call the base class' beforeFilter() since I was overloading it in my ImagesController

class ImagesController extends AppController {

    var $name = 'Images';
    var $helpers = array('TinyMCE');

    function beforeFilter(){
        parent::beforeFilter(); // <-- here
        if(!isset($this->params['admin'])) {
            $this->Session->setFlash(__('Access denied.', true));
            $this->redirect(array('controller'=>'users','action'=>'login','admin'=>false));
            exit();
        }    
    }

    function index() {
        $this->Image->recursive = 1;
        $this->set('images', $this->paginate());
    }

}


Answered By - Nasreddine
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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