Thursday, December 2, 2010

Re: Have my own Controller::var variable that is not overridden by descending AnotherController::var (but merged)? --psybear

Thanks for pointing me into the right direction! :-)

On Thu, Dec 2, 2010 at 11:56 AM, Amit Badkas <amit.sanisoft@gmail.com> wrote:
> Hi,
> Controller does merging of 'uses', 'helpers' and 'components' only by
> default, please have a look at __mergeVars() method in
> cake/libs/controller/controller.php
> Amit Badkas
> PHP Applications for E-Biz: http://www.sanisoft.com
>
>
> On Thu, Dec 2, 2010 at 3:53 PM, psybear83 <psybear83@gmail.com> wrote:
>>
>> Hey everybody
>>
>> I know that CakePHP applies some magic to inheritance. So when having
>> a class...
>>
>> class AppController extends Controller {
>>  var $uses = array('Model', 'AnotherModel');
>> }
>>
>> ...and then extending another one from it...
>>
>> class AnotherController extends AppController {
>>  var $uses = array('YetAnotherModel');
>> }
>>
>> ...we don't end up with AnotherController::uses being...
>>
>> array('YetAnotherModel')
>>
>> ...(as PHP would normally do it), but with
>>
>> array('Model', 'AnotherModel', 'YetAnotherModel')
>>
>> This is very nice! But I wonder how I can use this magic for my own
>> class variables? E.g. I want AppController::filters to be
>> array('Filter1', 'Filter2') and then for UsersController I want to add
>> 'Filter3', then normally I would have to use the beforeFilter:
>>
>> UsersController extends AppController {
>>  function beforeFilter() {
>>    $this->filters[] = 'Filter3';
>>  }
>> }
>>
>> But this isn't very beautiful, so I'd rather use the CakePHP magic
>> mentioned above. But how could I do this? Is there an easy way to tell
>> CakePHP to treat "filters" the same way as "uses" etc.?
>>
>> Thanks a lot for help
>> Josh
>>
>> Check out the new CakePHP Questions site http://cakeqs.org and help others
>> with their CakePHP related questions.
>>
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> 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?hl=en
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> 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?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

No comments: