tags:

views:

295

answers:

2

I don't get this: They say, it is good to make a "Base Controller" that instantiates the database and session:

// Base Controller code
$this->db = Database::instance($db_group);
$this->session = Session::instance();
// Now in any controller which extends Base Controller
$var = $this->session->get('var');
$query = $this->db->query('SELECT * FROM `table`);

So I would just make a controller class like any other controller, and then just let all my other "real" controllers inherit from this one, so that they have a database connection and a user session?

A: 

yup, that's true...

Fortega
+2  A: 

In Kohana, I do all my db work in my models. You can grab the DB object in the model just by doing

$this->db

Same goes for many of the other objects, for example $this->uri. My implementation of the MVC pattern means that all my db work is in my models, I'm not sure if this is the best way to do it but it works for me.

As for sessions, you can always use the static methods to get a singleton like

$mySession = Session::instance();

I'm pretty sure all/most of the helpers/libraries have a similar way of using them - initiate them from $this or use the static method.

alex