I would like to pass a variable from one controller function to an other. In other words, how can I access the variable from an other function, within the same controller?
Thanks
As Pascal mentioned, one way is to set a property on the object:
class CategoriesController extends AppController
{
public $foo = '';
public function index()
{
$this->foo = 'bar';
}
public function view($id = null)
{
$baz = $this->foo;
$this->set('baz', $baz);
}
}
Or pass it as argument:
class CategoriesController extends AppController
{
public function index()
{
$foo = "bar";
$this->view($foo)
}
public function view($param)
{
$this->set('bar', $param);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With