Tuesday, February 1, 2011

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

Well, for better or for worse the core developers don't spend a ton of
time writing on this mailing list. I'd like to know the rationale
behind certain decisions too, but sometimes we just have to take a
hard look at the code ourselves. :)

If I had to guess about __mergeVars() in particular (after a cursory
read of the code), it's probably restricted to AppController and the
plugin app controller (if applicable) just to make controller loading
easier. Since you can't easily deduce the plugin a controller is in
just by looking at the name, that makes it harder to load the
controller on demand. For example, if you have
AdministratorsController in your 'admin' plugin that extends
PeopleController in your 'users' plugin, it's nearly impossible to
guess which plugin PeopleController is from. And if you don't know the
plugin you can't load the controller. I know that's a pretty bad
pratice (extending classes between plugins), but it's a possibility
nonetheless. Since __mergeVars() restricts itself to AppController and
the AppController for the current plugin, then there's no guess work
needed. And since extending controllers beyond the AppController
relationship isn't really in the docs and not the "official" way to do
things, there probably hasn't been much impetus to change the
behavior.

Again, just me throwing a guess out there, but it does make sense (I
think).

- Jamie

On Feb 1, 4:32 am, Joshua Muheim <psybea...@gmail.com> wrote:
> Thanks, guys (especially to Tilen for his constructive feedback on my
> posting habits ;-) ).
>
> It seems to me I often run into limitations of CakePHP that I hope I
> can't be the only one who faced them yet and that there's a well known
> work-around already. In fact, I often seem to be the  only person who
> had the need for them yet, and that's sometimes a bit surprising to
> me, because I'm definitely not creating very high-end-featured
> websites with CakePHP yet, and in those cases I'm just interested in
> knowing the reason why those features aren't available in CakePHP (for
> which I'm sure there are diligent thoughts behind these decisions).
> I'm just the kind of person who's not satisfied with only the fact
> that something IS or ISN'T, but rather is interested in WHY IT IS or
> ISN'T.
>
> So to get back to my question I'd really like to know WHY
> __mergeVars() only supports "pseudo inheritance" from AppController
> and doesn't do it e.g. recursively through the whole inheritance-chain
> down to AppController. Maybe it's a performance issue? Maybe it's
> planned for a next release? Sadly the inline documentation of CakePHP
> codes isn't very exhaustive which is pitty because THERE's the place
> to put such "business decisions" when there's no other place for such
> informations (or maybe I haven't found this resource yet?).
>
> Anyway, no offense to anybody. I don't want to bother anyone or strain
> this mailing list, so if my questions really don't fit here I'm happy
> somebody's telling me this and I will think about what I could change
> in my habits so everybody is happy. I'm using forums and similar
> communities for quite a long time now, and I never had problems of any
> sort, but maybe things run a little different here. Thanks, Tilen, for
> subtly pointing me to this problem with your comment. ;-)
>
>
>
>
>
>
>
> On Tue, Feb 1, 2011 at 4:04 AM, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> > 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 Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd 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 athttp://groups.google.com/group/cake-php

--
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

No comments: