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

查看:31
本文介绍了在 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 的值直到运行时才知道,所以我不认为 bootstrap.php 是一个选项.

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天全站免登陆