• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Self written class can acces controller functions (Solved)

#1
[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

#2
[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

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

Thank you verry much inSiteFX!! =))

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.