gpt4 book ai didi

cakephp - Cake PHP 组件中的“设置”

转载 作者:行者123 更新时间:2023-12-02 10:52:45 25 4
gpt4 key购买 nike

如何使用Set 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 引用传递给组件的启动函数。您需要在组件中保留引用,以便稍后在自定义函数中使用。

参见此处http://book.cakephp.org/1.3/en/view/996/Creating-Components#MVC-Class-Access-Within-Components-998

关于cakephp - Cake PHP 组件中的“设置”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10229710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com