我添加了一个函数来检查我的AppController的语言参数
function beforeFilter(){
if(Configure::read('Config.language') == 'ara'){
$this->layout = 'rtl-layout';
} else {
$this->layout = 'ltr-layout';
}
}
但它在我的其他控制器中不起作用?
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());
}
}
请帮助我,这让我疯狂。
答案 0 :(得分:6)
我忘记调用基类“beforeFilter()
,因为我在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());
}
}