在CakePHP中创建全局变量的最好方法是什么? [英] What is the best way to create global variables in CakePHP?

查看:200
本文介绍了在CakePHP中创建全局变量的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CakePHP中创建一个全局变量。如果我在我的app_controller.php中定义了一些东西像

I'd like to create a global variable in CakePHP. If I define something in in my app_controller.php like

var $varName

我可以访问

$this->varName

从我的控制器,但我不能得到它从模型。

from any of my controllers, but I cannot get to it from models.

如何创建一个可以从模型中访问的全局变量?

How can I create a global variable accessible from the models?

$ varName的值在运行时之前是未知的,所以我

The value of $varName isn't known until runtime, so I don't think bootstrap.php is an option.

推荐答案


CakePHP的新配置类可以是
用于存储和检索应用程序
或运行时特定值。这个类允许你
存储任何东西,然后在
中使用你的代码的任何其他部分

CakePHP’s new Configure class can be used to store and retrieve application or runtime specific values. Be careful, this class allows you to store anything in it, then use it in any other part of your code

这篇关于在CakePHP中创建全局变量的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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