如何在cakephp的帮助文件中使用公共变量 [英] how to use public variable in helper file of cakephp

查看:156
本文介绍了如何在cakephp的帮助文件中使用公共变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cakephp中创建了一个助手,并在AppController.php文件中定义了一个全局变量。

I have created a helper in cakephp and defined a global variable in AppController.php file.

AppController.php

AppController.php

public $testVar = null;

我想在我的帮助文件中使用这个变量。

I want to use this variable in my helper file. How can do this?

推荐答案

你不需要传递额外的变量。
静态直接访问AuthComponent:

You don't need to pass around an extra variable. Directly access AuthComponent statically:

echo AuthComponent::user('username');

等。

也不注意,因为它首先检查存在(您需要使用数组在这里手动断言。

Note: This is also notice-free as it checks on the existence first (which you would need to manually assert with using arrays here.

这篇关于如何在cakephp的帮助文件中使用公共变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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