jump to navigation

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() {}
}

Advertisements

Comments»

1. AD7six - March 27, 2006

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

2. gwoo - March 28, 2006

this is already implemented in the core

3. rossoft - March 29, 2006

ok, know I see that you can have $components and $helpers directly in AppController and will be merged with your custom controller automatically


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: