Welcome Guest, Not a member yet? Register   Sign In
Erkana My_Controller quick question
#1

[eluser]efx[/eluser]
I'm having trouble creating a controller than extends the auth_controller. I get the fatal error: Call to a member function view() on a non-object in F:\web\www\mush\system\application\controllers\test.php on line 12

The code for the controller is:
Code:
<?php

class Test extends Auth_Controller {

    function Test()
    {
        parent::Auth_Controller();    
    }
    
    function index()
    {
        $this->load->view('welcome_message');
    }
}
?>

MY_Controller lib:
Code:
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');

/*****
  * This class provides a set of base Controller classes to be utilized with ErkanaAuth
  * @author     Michael Wales
  * @email      [email protected]
  * @filename   MY_Controller.php
  * @title      ErkanaAuth Controller Library
  * @url        http://www.michaelwales.com/
  * @version    1.0
  *****/

// Controllers accessible by everyone, regardless of login status
class Public_Controller extends Controller {
        
    function Public_Controller() {            
        parent::Controller();
        // Get the user data, in case they are logged in
        $this->data->user = $this->auth->get_user($this->session->userdata('user_id'));
    }
    
    // This function is used to prevent a user from accessing a method if they are logged in
    function no_user_access() {
        if ($this->data->user !== FALSE) {
            redirect('');
        }
    }
}

// Controllers only accessible by logged in users
class Auth_Controller extends Public_Controller {
    function Auth_Controller() {
        if ($this->data->user === FALSE) {
            // The user is not logged in, send them to the homepage
            redirect('user/login');
        }
    }
}

// Controllers only accessible to logged in users that are admins
class Admin_Controller extends Public_Controller {
    function Admin_Controller() {
        parent::Controller();
        if (($this->data->user === FALSE) || ($this->data->user->role != 'admin')) {
            redirect('user/login');
        }
    }
}

It's gotta be something simple that i'm missing.
Ive tried both Test() & __construct() for the constructor call. Any ideas?
#2

[eluser]Rick Jolly[/eluser]
You're missing the call to parent:Tongueublic_Controller(); in the Auth_Controller constructor. You should be calling parent:Tongueublic_Controller(); instead of parent::Controller(); in the Admin_Controller constructor.
#3

[eluser]efx[/eluser]
Legend! Cheers mate Smile
#4

[eluser]lookatthosemoose[/eluser]
muchas gracias!
#5

[eluser]Michael Wales[/eluser]
Yeah - sorry about that, I think that's a minor mistake in the downloadable version from my blog. It will be fixed soon - everything on my blog is getting an overhaul.




Theme © iAndrew 2016 - Forum software by © MyBB