I’m new to the MVC concept, and somewhat new to PHP.
Question 1
Before every controller is loaded, I’d like to run a function which checks to see if a database-table exists. Is the proper way to do that with hooks?
Question 2
Before every controller is loaded, I’d like to set a few variables which are determined by a call to the db. How/where is that supposed to be done in a MVC (Kohana) setup?
Edit: Regarding Kohana v2.3.4
For Question 1 & 2, I would use hooks for these. Hooks allow you to have code executed at various times throughout the framework’s startup and tear down phases. Checkout the documentation page on hooks on Kohana’s site. The events documentation has all the events listed that you can use throughout the framework.
Question 3: You don’t ever really have to use a constructor in your controllers. One reason to do it may be if you have several actions that need the same object instances and things like that, you can create them once in the constructor.