Error creating new libraries |
[eluser]Marian Alexandru[/eluser]
I have a library call func.php: Code: class Func { When I call func->content() it get me this error: Code: A PHP Error was encountered If a write Code: public function content() { I don't get that error. So my question is: I'm obligated to use $this->CI = & get_instance(); in every function if I want to load a view?
[eluser]CodeIgniteMe[/eluser]
Code: $this->CI = & get_instance(); Code: $this->CI =& get_instance();
[eluser]Marian Alexandru[/eluser]
If I put Code: $this->CI =& get_instance(); I don't resolv the problem. And Code: $this->CI = & get_instance(); isn't different from Code: $this->CI =& get_instance();
[eluser]PhilTem[/eluser]
It's odd. I never had problems with libraries and a reference to the CI super-object by using the same code you did. But let's try to narrow down on the source of your problem. I just got some questions: - Which PHP version are you running on? - Does it work if you replace Code: var $CI Code: public $CI - Try to use it statically with Code: static $CI Code: self::$CI =& get_instance();
[eluser]Narf[/eluser]
Your code is perfectly fine and nothing mentioned so far (except for the PHP version in use) can be related to the error you're getting. The problem is that your constructor isn't being executed on class (library) instantiation and that's indeed a CI bug. Until the fixed version is released, you can load your library with dummy (but non-NULL) parameters passed to it, like this: Code: $this->load->library('func', array());
[eluser]Marian Alexandru[/eluser]
My php version is 5.3.8. Thx PhilTem, with your code I solve the problem. If I put Code: $this->load->library('func', array()); I still get that error.
[eluser]Narf[/eluser]
Eh ... if that fixes your problem - you're deffinately not showing all the code. ![]()
[eluser]PhilTem[/eluser]
I'm confused, too. The number of lines didn't match the error-log, too (something with an error on line 40, even though the posted code only has like 15 lines). @Marian Which part solved your problem? Using 'static' or telling PHP $CI is public rather than just a var?
[eluser]Marian Alexandru[/eluser]
Here are the first 40 lines of library Code: <?php I call the func->content() from a controller named logat.php
[eluser]Narf[/eluser]
Well, it would've worked if you called $this->CI->m_logat, instead of $this->m_logat. |
Welcome Guest, Not a member yet? Register Sign In |