Welcome Guest, Not a member yet? Register   Sign In
How to use a function from a other controller?
#7

[eluser]Rick Jolly[/eluser]
I don't usually disagree with Colin, and this is largely personal preference, but I don't think models should redirect. Models should be as generic and implementation independent as possible. It's also more transparent to have the redirect in the controller.

I think your code could be simplified:
Code:
function details() {
        // $secured_page = TRUE;
        // where is $permitted_role used?
        // $permitted_role = 100;
        // you know this is secure. You just set it above
        // if ($secured_page == TRUE) {
            // place variables

            // you can set these as class variables in the constructor instead of every method
            //$username = $this->session->userdata('username');
            //$password = $this->session->userdata('password');
            // check credentials in database
            if ($this->your_model->check_credentials($this->username, $this->password)) {
                            echo "do this";
            } else {
                            // redirect to $error_page
                    }
        }
    }

Edit: If you'd like another way of securing controllers, you could look at controller inheritance. You could have a parent controller do all the checks and redirect if necessary all before your child controller executes. That way you don't have to handle the repetition in each of your controllers/methods.


Messages In This Thread
How to use a function from a other controller? - by El Forum - 08-13-2009, 05:01 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 05:34 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 05:45 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 05:58 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 06:01 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 06:16 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 06:22 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 06:25 PM
How to use a function from a other controller? - by El Forum - 08-13-2009, 10:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB