Imagine a typical CakePHP application, in which a Controller passes various bits of data to the View using $this->set
in the typical way:
class ThingsController extends AppController {
function test() {
$this->set('someparam', 5);
}
}
If the corresponding View was to define and use a small helper function which outputs some HTML, is there any way to access that variable $some_param
from within the function? I would have thought you could just access it as a global variable, but it always come out with the value NULL
.
<?php
function helper_function() {
global $someparam;
echo var_dump($someparam); // Just prints NULL
}
?>
<h1>I am a View!</h1>
<?php helper_function(); ?>
To be honest, an even simpler use case is for the helper_function
to be able to access things like the $html
and $javascript
helpers.