CodeIgniter Forums
Self written class can acces controller functions (Solved) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Self written class can acces controller functions (Solved) (/showthread.php?tid=40342)



Self written class can acces controller functions (Solved) - El Forum - 04-05-2011

[eluser]Unknown[/eluser]
Dear Codeigniter Community,

I'm new to the forums so let me introduce meyself quickly, Hi I'm Marc 21 years old and starting web developer.

I currently have a minor problem that is easy to fix but I can't seem to find it, so perhaps you can give me a quick shout what I'm doing wrong.

I made an class and put it in the library folder and loaded it in my controller ( that works fine ).

Now the problem is that in this self written class I'm not able to preform something like :

$this->load->view('page');

Feedback:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: member::$load

Filename: libraries/member.php

Line Number: 13

Fatal error: Call to a member function view() on a non-object in C:\wamp\www\ci_bpm\application\libraries\member.php on line 13

What I understand so far is that my class is offcourse not a CI controller and therefore not able to preform the load function. Is there a way to acces these functions or to reference to the controller where the function of this class is being called ?

Thank you in advance!!!

Marc


Self written class can acces controller functions (Solved) - El Forum - 04-05-2011

[eluser]InsiteFX[/eluser]
Code:
private $CI;

class Your_class_name {

    Public function __construct()
    {
        parent::__construct();

        $this->CI =& get_instance();
    }
}

Code:
$this->CI->load->view('page');

InsiteFX


Self written class can acces controller functions (Solved) - El Forum - 04-06-2011

[eluser]Unknown[/eluser]
Aah the get_instance(); did wonders !!

Thank you verry much inSiteFX!! =))


Self written class can acces controller functions (Solved) - El Forum - 08-11-2011

[eluser]sineld[/eluser]
thanks. worked for me too.