A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearController inheritance in Cake PHP? - page 1
User InfoPosts
Controller inheritance in Cake PHP?#1
Has anyone attempted this? Is it possible, and if so, what kind of problems will I run into if I try to accomplish it?

posted date: 2008-12-11 10:00:00


Re: Controller inheritance in Cake PHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-11 10:00:01


Re: Controller inheritance in Cake PHP?#3
Please be more specific with your question and explain the problem you are trying to solve.

posted date: 2008-12-11 10:12:00


Re: Controller inheritance in Cake PHP?#4
Why not try? At least, it's already being done with the Controller -> AppController -> MyController classes.

posted date: 2008-12-11 11:01:00


Re: Controller inheritance in Cake PHP?#5
Sure, you can easily subclass controllers in Cake.. and then you'd typically utilize their hook function such as 'beforeFilter', 'afterFilter', etc. to add runtime logic to your controllers.. I typically put at least 1 abstract controller between cakes controller and the final controller that you configure in the route.

posted date: 2008-12-11 12:23:00


Re: Controller inheritance in Cake PHP?#6
I have put an additional layer between the AppController and some special controllers in an app.The only problem you'll run into is the merging of the $helpers and $components class attributes. In CakePHP, overriding those variables in your controllers will not overwrite those set by the AppController, but it will merge them. This is done by a special method named __mergeVars() in the Controller base class, and it unfortunately does it only for the default controller structure. Your additional layer will not be merged correctly, if you want $helpers and $controllers inheritance from AppController down to your controllers.

posted date: 2008-12-17 01:55:00


Re: Controller inheritance in Cake PHP?#7
If you goal is to share logic between controllers:add the logic to the AppController to share it with all the controllers in your app.make a component and add that to $this->components for the controllers you want to share it. Adding additional inheritance between controllers should only be concidered as a last resort, as you have to pay extra attention to how components and helpers are handled. E.g. you must manually merge $this->components & $this->helpers with the AppController and the controller you are inheriting from.

posted date: 2009-01-08 05:55:00


Re: Controller inheritance in Cake PHP?#8
You will run into issue with $components and $helpers properties not merging and instead overwriting. Be sure to define protected $_mergeParent = 'YourParentClass' to have this done properly. The default value for this is 'AppController'.Source code:http://api.cakephp.org/2.4/source-class-Controller.html#294-301

posted date: 2013-09-10 04:31:00


Re: Controller inheritance in Cake PHP?#9
where should i add this protected $_mergeParent = 'YourParentClass' ?

posted date: 2014-06-02 22:01:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.