App-Wide components / helpers March 27, 2006
Posted by rossoft in CakePHP.trackback
You can set another array variable in app_controller, then merge it
at the constructor with the $components / $helpers variable.
class AppController
{
/** Array of common components for all controllers */
var $appComponents = array(’rdAuth’,’session’);
/** Array of common helpers for all controllers */
var $appHelpers= array(’Html’, ‘Javascript’);
function __construct()
{
$this->components=am($this->appComponents,$this->components);
$this->helpers=am($this->appHelpers,$this->helpers);
parent::__construct();
}
}
In your own controller, you can set the others helpers/components that
you use
class MyController extends AppController
{
var $components=array(’pdf’);
var $helpers=array(’myhtml’);
function test() {}
}
Gets around inheritance problems nicely, I wonder how many other’s have implemented something like this?
I think I should get more active with blogging my code
Cheers,
AD
this is already implemented in the core
ok, know I see that you can have $components and $helpers directly in AppController and will be merged with your custom controller automatically