Some functions in Controller |
hi, I have any controllers with some functions
PHP Code: class Foo extends CI_Controller How not to write one and the same function all the time?
1. you can create application/core/MY_Controller.php
and all you controllers will extend MY_Controller instead of CI_Controller MY_Controller.php: PHP Code: class MY_Controller extends CI_Controller { 2. or you can use models put your function in a model
Depending on the function of the method, putting it in a Library might be the best solution. Personally, I'd do that anyway for most things, then you could still use it within MY_Controller if needed.
(11-17-2017, 09:32 AM)kilishan Wrote: Depending on the function of the method, putting it in a Library might be the best solution. Personally, I'd do that anyway for most things, then you could still use it within MY_Controller if needed. I was find example with models... Perfectly. I was create new Library. (11-17-2017, 11:16 AM)Narf Wrote:(11-17-2017, 08:31 AM)neuron Wrote: In Documentation : PHP Code: class MY_Input extends CI_Input {
(11-18-2017, 05:54 AM)neuron Wrote: In Documentation : And as the documentation says "If you need to use a constructor in your class make sure you extend the parent constructor:" If you don't have work that must happen in a constructor then you don't need to define a constructor only for purpose of calling parent::__construct(). PHP will take care of that automatically. However, if you do define __construct() then you must explicitly call parent::__construct() |
Welcome Guest, Not a member yet? Register Sign In |