In KO2, I had a file called libraries/CUSTOM_Controller.php, in which I kept common methods that I wanted to be available t开发者_运维问答o all controllers.
Is there a similar way to do this in KO3? I don't see anything in the docs (such as they are) about overriding the controller.
Thanks!
Here comes the philosophy of Kohana 3. If you look in this SYSPATH/classes/controller.php
file you'll see that there is defined empty class wich extends Kohana_Controller
class. That means you can overwrite Controller
class.
Make your own Controller class located APPPATH/classes/controller.php
(kohana will always search file in APPPATH
first).
class Controller extends Kohana_Controller {
public function myMethod(){
// ...
}
}
$this->myMethod()
will be available in all your controllers and nothing from Kohanas core will be lost.
精彩评论