Monday, January 31, 2011

Re: SecondController extends FirstController extends AppController: not supported? --psybear

On Jan 31, 2011, at 08:24, psybear83 wrote:

> I'm refactoring an application with some controllers and wanted to
> "divide" them into a group X (that needs some components) and a group
> Y that needs some other components. My idea:
>
> class AppController {
> var $components = array('Html', 'Form');
> }
>
> class XController extends AppController {
> var $components = array('X1', 'X2');
> }
>
> class YController extends AppController {
> var $components = array('Y1', 'Y2');
> }
>
> Now every other controller should inherit from XController or from
> YController like this:
>
> class SomeXController extends XController {
> var $components = array('Bla');
> }
>
> I expected XController now to have loaded the following components:
> Html, Form, X1, X2, and Bla. But sadly it doesn't have all of them! It
> seems CakePHP doesn't allow controller inheritance over more than only
> 1 level. Is this true? Is there any known work-around?

From a purely PHP standpoint, your XController's var $components is overwriting your AppController's var $components, and so on. Not knowing about __mergeVars() which Jamie talked about, I'd have suggested you implement a constructor in each of your classes, which calls the parent constructor and then takes care of merging your newly-desired components into the existing components array. PHP has some array functions that should do the trick.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate