Constructor Controller (SQLite User Defined Functions) |
[eluser]Veehmot[/eluser]
Hey! I need to know how can I call some logic for the application startup. Basically, what I'm trying to do is to create some user defined functions for SQlite, to handle REGEXP. I had done that already, by calling directly Code: sqlite_create_function($this->db->conn_id, 'regexp','regexp'); Quote:Undefined property: Creator::$dbYes, of course I'm extending Controller. Code: <?php What's the correct way to process some logic at the beginning of the application? Thanks!
[eluser]Veehmot[/eluser]
My temporary solution is to add that line under Code: $this->_ci_initialize(); Thanks,
[eluser]Veehmot[/eluser]
Oh c'mon guys, this is an OpenSource project, the only support I have is this forum.
[eluser]BrianDHall[/eluser]
Why not use the constructor of your controller, or if you prefer it be available for all controllers use the constructor of a MY_Controller? If you prefer you can put your logic in a library/helper/plugin and autoload it (through the autoload.php file in your config directory, of course). That would work too. Personally, I just use the constructor method. That's what constructors are for, after all.
[eluser]Veehmot[/eluser]
I want it to be available for all controllers. What do you mean that I can use MY_Controller?
[eluser]BrianDHall[/eluser]
OK, then a MY_Controller will be of use to you. It isn't the only way to do it, but it's very common way of handling it. Basically you create a MY_Controller controller. The trick is then in all your other controllers instead of having: Code: class Catalog extends Controller { You change them to be: Code: class Catalog extends MY_Controller { Now in your MY_Controller you can put in anything you want to be automatically available to all your controllers (or at least the ones you chose to use the MY_Controller. So in your MY_Controller constructor you can put your call to sqlite_create_function() and define your regexp() function. Then in all of your controllers that you've made to extend MY_Controller you could call $this->regexp(), and your sqlite function will have already been executed for you and you will be ready to go! This MY_Controller technique is typically used to create header/footer/etc variables, user authentication features, and all sorts of things like this. Here's the basic manual entry on this: http://ellislab.com/codeigniter/user-gui...asses.html
|
Welcome Guest, Not a member yet? Register Sign In |