本文介绍了'设置'在组件的蛋糕PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在组件中使用功能cake php?
How to use Set function inside components in cake php ?
class TestComponent extends Object
{
//etc
$this->set('User', $user);
}
我收到错误
Fatal error: Call to undefined method TestComponent::set()
如何更正此问题?
推荐答案
function startup($controller) { $this->controller = $controller }
function something() {
$this->controller->set('User',$user);
}
Cake将Controller引用传递给组件的启动函数。
Cake passes the Controller reference to the startup function of a Component. You need to keep a reference in your component to use later in custom functions.
请参阅这里
这篇关于'设置'在组件的蛋糕PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!