Question:
How do I access variables from another controller
?
For example:
I have an controller X
, and in the index
action, I create a variable (or a constant). From controller Y
, I want to access the variable (or constant) value of controller X
.
Is it possible to do that? Remembering that each action of each controller
, in my application, will have a variable that must be accessible from another controller
.
Controller ExampleX
class ExemploXController
{
$dependencias = array("index","listar");
public function index()
{
echo "Index";
}
public function funcaoX()
{
echo "Funcão X";
}
public function listar()
{
echo "listando";
}
}
Controller ExemploY
class ExemploYController
{
$dependencias = array("index","atualizar");
public function index()
{
//pegar o valor da variável $dependencias da controller ExemploXController
$dependency[] = ExemploXController->dependencias;
}
public function funcaoY()
{
echo "Funcão Y";
}
public function atualizar()
{
echo "atualizar";
}
}
Answer:
Hello, can you create a requestAction
. With it you can use it both on the same controller and on other controllers, but don't forget to create the cache element .
http://book.cakephp.org/2.0/en/controllers.html#Controller::requestAction