views:

141

answers:

1

Hi All,

In KO2, I had a file called libraries/CUSTOM_Controller.php, in which I kept common methods that I wanted to be available to 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!

+3  A: 

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.

Anpher
Perfect, thanks! One question though - is there any way to do this via the app folder, since I use my sys folder for multiple apps, and may need different methods available in different apps?
Eli
You should never modify system files, the extension should be added to the `application/classes/` folder.
shadowhand

related questions