Welcome Guest, Not a member yet? Register   Sign In
check controller status in DB before executing
#1

[eluser]Blux[/eluser]
Hello everybody ..
This is my first project with CI, loving it by the way, and i hope someone could help me with my problem. =)

basically what i want to do is to make my model check on the database before running a controller.
i'm using a function in my model that run a check if certain database record exist or not, if not it shows an error message, or else continue and run the controller !

Code:
public function load($controller)
{
     $query = $this->db->query("SELECT * FROM table WHERE name = '$controller'");
    $result = $query->result_array();

    if($query->num_rows() < 1){
        show_error("could not load {$controller}, no record in database. Please make sure it is installed!");
    } elseif($result[0]['status'] != 1) {
        show_error('can not run unactivated controller. Please activate.');
    } else {
        
        // calling the controller ..
        
    }
}

i'm using Matchbox, and the controllers are in /application/modules folder ..

i tried using Wick but it didn't work for me ...

any thoughts would be appreciated =D
thank you in advance =)
#2

[eluser]davidbehler[/eluser]
You could use a pre_controller hook: http://ellislab.com/codeigniter/user-gui...hooks.html
#3

[eluser]Blux[/eluser]
Thank you for the replay. However, i think a hook won't do what is in my mind.
i need it to only be activated for the controllers in /application/modules/some_module/controllers/ ..
not the ones in /application/controllers/ ..

i did try what you have suggested, and there was a problem and didn't work. It gave me:
Fatal error: Class 'Model' not found in /Applications/MAMP/htdocs/CI/system/application/models/load/load_Model.php on line 11


thank you again =)
#4

[eluser]Blux[/eluser]
no one can help me with this ?
anything will do ..

i just need to check before processing the controller
can i change the router.php or my_router.php or even the loader.php ?
#5

[eluser]Blux[/eluser]
solved! =D

by adding a peace of code in My_Router.php
Code:
if(isset($path2[7])){
    // any code to inturupet the calling of any module
    // $path2[7] will check the file name of the module
}

not the best way, but it will help in my case, for now =)




Theme © iAndrew 2016 - Forum software by © MyBB