Welcome Guest, Not a member yet? Register   Sign In
Autoload problem
#1

[eluser]weedy[/eluser]
EDIT: Solved, see post #4 for info.
http://ellislab.com/forums/viewthread/79175/#397322

I put core session class to autoload, it works in a pre-controller hook, but calling it in the controller results in "Message: Undefined property: User::$session" and "Fatal error: Call to a member function userdata() on a non-object in /usr/local/www/casting/system/application/controllers/user.php on line 21".

Any ideas what might be causing it?

(and yes I'm a CI newb)

Below the code:
config.php
Code:
$autoload['libraries'] = array('database', 'session');

hooks.php
Code:
$hook['pre_controller'][] = array(
                                'class'    => 'Auth',
                                'function' => 'index',
                                'filename' => 'auth.php',
                                'filepath' => 'hooks',
                                );

hooks/auth.php
Code:
class Auth extends Controller
{
    function Auth()
    {
        parent::Controller();
    }
    function index()
    {
        $uri = $this->uri->uri_string();
        
        //check versus recurrency
        if($uri != '/user/login')
        {
            //id should be known
            if(!$this->session->userdata('id'))
            {
                //save current uri to redirect back to it after login
                $this->session->set_userdata('redirect' , $uri);
                 redirect('/user/login');
            }
        }
    }
}
Note - I had to extend the controller in order to get $this->session working here $CI & = get_instance() didn't work at all (any ideas here too? ).

controllers/user (constructor is blank apart from parent::Controller call)
Code:
function login()
{
    $email = $this->input->post('email');
    $password = $this->input->post('password');
    
    if($email && $password)
    {
        $this->load->model('user_model', 'user');
        if($auth = $this->user->auth(array('email' => $email, 'password' => $password)))
        {
            foreach($auth as $key => $value)
            {
                $this->session->set_userdata($key, $value);
            }
            if($redirect = $this->session->userdata('redirect'))
            {
                redirect($redirect);
            }
            else
            {
                redirect('');
            }
        }
    }
    $this->load->view('user/login');
}


Messages In This Thread
Autoload problem - by El Forum - 05-11-2008, 05:31 AM
Autoload problem - by El Forum - 05-11-2008, 07:28 AM
Autoload problem - by El Forum - 05-11-2008, 08:00 AM
Autoload problem - by El Forum - 05-11-2008, 08:15 AM
Autoload problem - by El Forum - 05-11-2008, 08:42 AM
Autoload problem - by El Forum - 10-01-2008, 07:56 PM
Autoload problem - by El Forum - 10-02-2008, 12:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB