Welcome Guest, Not a member yet? Register   Sign In
Non-accessible function from controller (PHP 5)?
#1

[eluser]IanMcQ[/eluser]
Hi,

My site was working fine until I switched servers, which had PHP 5. On one of my VIEWS, I call a function "parsecode()" which is defined in the controller. Back on PHP 4 I was easily accessing this as $this->parsecode() in my view. But now, when I try to access the function that way, it dies with an "undefined instance in CI_Loader::parsecode." I had to put parsecode() in my view file before I could use it again.

Is there are workaround for this? I'm a traditional PHP 4-er and am still getting up to date with the new programming principles of PHP 5 and expanded OOP functionalities.

Thanks in advanced,

Ian
#2

[eluser]jcopling[/eluser]
I'm not sure about best practices, but you should be able to load CodeIgniter into a variable and then call your function from the variable by placing this inside the view:
Code:
$CI =& get_instance();
$CI->parsecode();

If anyone has a better idea, I'd be interested what the best way to do this may be, but this solution should at least get you working
#3

[eluser]wiredesignz[/eluser]
With CI under PHP4, the Controller extends the Loader class making it available to Views.

Using PHP5, the Controller and Loader are separate objects, thus your View no longer has direct access to the Controller.

The fix is to write code in a fashion that does not access the Controller methods directly in Views, however you can pass specific objects to your Views as variables instead.

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB