是否可以通过 $this->set('variable_name', 'some_value')
跟踪所有设置变量
在 Controller 的方法本身。
实际上我有一个调用其他几个方法的方法,每个子方法都设置要查看的值。现在我无法跟踪同一个键是否在 main 方法中设置了两次。
例子
function beforeFilter()
{
$this->set('key1', 'viable value');
}
function reqMethod()
{
$this->extendMethod1();
$this->extendMethod2();
$this->extendMethod3();
$this->extendMethod4();
$this->extendMethod5();
$this->extendMethod6();
// Want to track all set variable (key) here.
}
private function extendMethod1()
{
$this->set('key1', 'unknow value');
}
这里可能会将 key1(错误地)设置为另一种方法。 非常感谢任何帮助。
最佳答案
Controller::set() 只是将值添加到“viewVars”属性,因此要调试所有这些变量,您只需执行以下操作:
debug($this->viewVars);
您可以通过查看源代码自己发现这一点吗?
关于php - cakephp 知道 Controller 本身的所有设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15831152/