I am having problems with trying to set global variables with my CakePHP 2.2.2 app. I have defined the following inside my AppController :
App::uses('Controller', 'Controller');
class AppController extends Controller {
function beforeFilter() {
$MenuTest = "MENU TEST";
$this->set('Menu', $MenuTest);
} //End of beforeFilter()
}
This is meant to set $MenuTest as a global variable right? So I should be able to access $MenuTest on any controller or view I want? An less I am missing something?
App::uses('AppController', 'Controller');
class PagesController extends AppController {
public $name = 'Pages';
public $uses = array();
public function display() {
debug( $Menu);
die();
$this->render('home');
}//End of function display()
function test () {
echo $Menu;
echo 'This is testing a new link';
die();
}//End of function test()
}
When I load my page, all that debug gives me is a ‘null’. Again the same when I use the test function?
Please help? What I am doing wrong?
Thanks, Glenn
Controller::set()sets a view var, not a class var. If you want a class var inherited by all sub-classes you would do$this->Menu = 'Some value';and access with$this->Menu.