I wrote a question earlier trying to get around using a controller in Kohana, but I gave in and rewrote the file. So now, the I have this php script inside a Kohana controller. The view that the controller is rendering is ‘requiring’ a php file so I can perform some third-party functions. I was having a major issues with it and got to debugging. The problem seems that functions inside the included file cannot access variables outside the function from within that same file. It seems that Kohana is clearing the globals somehow???
example:
//controller.php
require_once("ccfunctions.php");
//ccfunctions.php
$test = 'something';
function test(){
global $test;
echo $test;
}
test();
//This does not produce anything
Any thoughts on this one?
EDIT:
Actually, the above example doesn’t work even from my view file that is being rendered. Forget the included file. I realize Kohana tries to enforce the MVC model, but this is ridiculous. Why cannot I not create a function and call a global variable from within my view file?
You need to specify
globalfor variable in both cases:Btw, it is really weird practice and I believe there are workarounds for any case without using
global