I don't think it's a good idea to access database in bootstrap. You cannot use models because they haven't yet been initialized. I think that you could extract the connection data and initialize connection and run queries using PHP's mysql_*
but that's an ugly thing.
However if you need to run certain action everytime your app is accessed I would suggest placing it in AppController
constructor (__construct
function).
class AppController extends Controller {
public function __construct() {
// do your magic here
// call parent constructor
parent :: __constructor();
}
}
class YourSpecificController extends AppController {
public function __construct() {
// call parent contructor (this) will cause your magic happen
parent :: __constructor();
// extra controller initialization instructions
}
}
If you don't declare constructor in extending class you won't even have to change anything since PHP will automatically call parent (AppController
) constructor.