Welcome Guest, Not a member yet? Register   Sign In
Getting "Undefined property" error message
#1

[eluser]Armando Ramos[/eluser]
Hi, I'm new to CI.

I recently created my own library file called "Error_handle.php" in "application/libraries" that handles any run time error.

I updated my autoload.php file to this:
$autoload['libraries'] = array('authorizor', 'error_handler');

Here is the code in which I call my the class from my library file:

Code:
function index()
    {
        if($this->authorizor->user_authorized())
        {
            $user = $_SESSION[session_id()];
            //print_r($user);
            try
            {
                $q = "";
                if($user[0]['Role']['name'] == 'admin')
                {
                    $q = Doctrine_Query::create()
                        ->from('Rsewrite_Map rm')
                        ->leftJoin('rm.User u');
                }
                else
                {
                    $q = Doctrine_Query::create()
                    ->from('Rewrite_Map')
                    ->where('u_id = ?', $user[0]['id'])
                    ->andWhere('disabled = ?', '0');
                }
                $rewrite_map = $q->fetchArray();
                //print_r($rewrite_map);
                
                $data['rewrite_map'] = $rewrite_map;
                $this->load->view("rm_records_view", $data);
            }
            catch(Exception $e)
            {
                $this->error_handler->get_error($e, $_SERVER['HTTP_REFERER']);
            }
        }
    }

However, I get the following error:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: RM_Records::$error_handler

Filename: controllers/rm_records.php

What am I doing wrong?
#2

[eluser]daelsepara[/eluser]
perhaps in the constructor section of your controller, you can place the line.

Code:
$this->load->library('error_handler');
#3

[eluser]Armando Ramos[/eluser]
Did that and it did not work.
#4

[eluser]mddd[/eluser]
Inside a controller or model, $this means: the CI object.
But inside a library, $this means: the library. You have to get the CI object and then call the other library through that object.

So you should change this:
Code:
$this->error_handler->get_error($e, $_SERVER['HTTP_REFERER']);
into this:
Code:
$CI =& get_instance(); // get a reference to the CI object
$CI->error_handler->get_error($e, $_SERVER['HTTP_REFERER']); // call the error through the CI object
#5

[eluser]Armando Ramos[/eluser]
It worked! Thanks for the help!
#6

[eluser]danmontgomery[/eluser]
[quote author="mddd" date="1276693125"]Inside a controller or model, $this means: the CI object.[/quote]

This is incorrect... $this represents whatever object you're currently working in. In the controller, it's the controller class. In the model, it's the model class. The model just inherits most of the controller's members when it's instantiated (See Model::_assign_libraries).




Theme © iAndrew 2016 - Forum software by © MyBB