'设置'在组件的蛋糕PHP [英] 'Set' in Components of Cake PHP

查看:126
本文介绍了'设置'在组件的蛋糕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.

请参阅这里 http://book.cakephp.org/1.3/en/view/996/Creating-Components#MVC-Class-Access -Within-Components-998

这篇关于'设置'在组件的蛋糕PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆