Welcome Guest, Not a member yet? Register   Sign In
Issue with hook and template library
#1

[eluser]xtremer360[/eluser]
I am coming across a weird error message that I've never come across before. When I load my login page I get the following error.

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$agent
Filename: libraries/Template.php
Line Number: 122

I am using Phil Sturgeon's template library for my codeigniter application. It is currently autoloaded. I've included the hook that I am using for my system because if I keep it I get the error message. If I comment it out then I don't get the error message. To the best of my knowledge there is no error with its 7 lines of code or the sys_prescript.php file.

application/config/hooks.php

Code:
$hook['pre_controller'] = array(
    'class'    => 'Sys_prescript',
    'function' => 'is_logged_in',
    'filename' => 'sys_prescript.php',
    'filepath' => 'controllers',
    'params'   => ''
);

application/controllers/sys_prescript.php

Code:
<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Sys_prescript extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

    public function is_logged_in()
    {
        $public_access = array('login', 'registration');    
        if (!in_array($this->router->fetch_class(), $public_access))
        {
            $user_id = $this -> session -> userdata('user_id');
            if (($user_id == FALSE) || (is_numeric($user_id) == FALSE) && (strlen($user_id) < 5))
            {
                redirect('login');
            }
        }
    }
}

application/controllers/login.php

Code:
&lt;?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Login extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this -> load -> model('user_login_model', 'login');
    }

    public function index()
    {
        $this -> template -> set_theme('saturn') -> set_layout(FALSE) -> build('admin/login');
    }
}

#2

[eluser]CroNiX[/eluser]
Hooks are not controllers.
#3

[eluser]xtremer360[/eluser]
What am I missing here then?
#4

[eluser]CroNiX[/eluser]
Your hook extends CI_Controller. They are just stand alone classes, or functions.

Just curious, didn't you have all of this working in your Admin_controller? Why change it?
#5

[eluser]xtremer360[/eluser]
Yes, but I wanted to go a different route. I've tried it both ways before and I prefer it this way but yeah of course the dreaded fix one error get another is presented.

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Sys_prescript::$router
Filename: controllers/sys_prescript.php
Line Number: 9

Fatal error: Call to a member function fetch_class() on a non-object in application/controllers/sys_prescript.php on line 9
#6

[eluser]CroNiX[/eluser]
Ok, well your different route is going to take you longer to figure out, which adds to the cost of your project for something that was already done and working. You must have a very understanding employer/client. It's not as straight forward as the admin_controller. If you've tried both ways, then you shouldn't be having this issue and know that standalone classes/functions/helpers don't know anything about CI until you tell it via get_instance(), just like a custom library/helper/etc.




Theme © iAndrew 2016 - Forum software by © MyBB