jack2684 Posted March 18, 2014 Share Posted March 18, 2014 (edited) I writing a new controller for myself. I notice that in admin contollers, there is a method like this, public function __construct() which seems override the __construct() method in AdminControllerCore. While in the front controllers, there is no such method. Why the admincontroller needs to override the __construct()? Is it some kind of security issue or something else? Can we just write the code in the init() method instead of __construct()? Edited March 18, 2014 by jack2684 (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted March 19, 2014 Share Posted March 19, 2014 it depends on what your admin controller needs to do. For example, if you are displaying a list of data from the database (like customers or orders), then you would use __construct to define where the data would be pulled from. Link to comment Share on other sites More sharing options...
vekia Posted March 19, 2014 Share Posted March 19, 2014 it's not a "override" if you use __construct function, it will be used also with __construct of parent element it's great feature in php , you can define own object params there, define some actions etc. Link to comment Share on other sites More sharing options...
jack2684 Posted March 19, 2014 Author Share Posted March 19, 2014 it depends on what your admin controller needs to do. For example, if you are displaying a list of data from the database (like customers or orders), then you would use __construct to define where the data would be pulled from. Can I implement those thing in "public function init()"? Link to comment Share on other sites More sharing options...
bellini13 Posted March 19, 2014 Share Posted March 19, 2014 You are asking me if you can use init() without stating what you are trying to do, so I can't answer your question. I would suggest you find a similar admin controller (that does what you are looking to do) and do what it does. Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2014 Share Posted March 21, 2014 Can I implement those thing in "public function init()"? in my opinion you can, and this is correct function for such things. __construction it's a constructor The "__construct" was introduced in PHP5 and it is the right way to define your, well, constructors (in PHP4 you used the name of the class for a constructor). You are not required to define a constructor in your class, but if you wish to pass any parameters on object construction then you need one. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now