Welcome Guest, Not a member yet? Register   Sign In
Call one controller from another controller
#3

[eluser]Prophet[/eluser]
Can't User just load image_model? I wouldn't be too concerned with code repetition, especially simple stuff like loading views.

Code:
class User extends Controller {

    function login() {

        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $this->load->model('user_model');
        $this->load->model('image_model'); //Autoload it if you call it often

        if ($this->user_model->authenticateUser($username, $this->_prepPassword($password))) {

            if ($query = $this->image_model->getAlbumsByUser(2)) {
                $data['albums'] = $query;
            }

            $sessiondata = array(
                'username' => $username,
                'authenticated' => true
            );

            $this->session->set_userdata($sessiondata);
            $this->load->view('user_view', $data);
        }
    }

Edit: If you really want to call Site->userView() from User, just have User extend Site (since Site sounds like it would have some generic methods that will be useful to many controllers throughout the site?)


Messages In This Thread
Call one controller from another controller - by El Forum - 08-14-2010, 07:50 PM
Call one controller from another controller - by El Forum - 08-15-2010, 02:07 AM
Call one controller from another controller - by El Forum - 08-15-2010, 02:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB