我是CodeIgniter的新手。我将它用于我的个人项目。在配置文件中使用模型常量(CodeIgniter)
我想遵循的事情之一是坚持最好的编码实践。其中之一是DRY规则(不要重复自己)。我尝试在适当的模型类中定义一些常量,并在代码中的其他地方使用它们,所以当涉及到一点改变时,它只能在一个地方完成。
我有这个类有哪几种常量,例如:
class Hero_attributes
{
const ID = 'id';
const NAME = 'name';
const LEVEL = 'level';
const MAG_LEVEL = 'maglevel';
const VOCATION = 'vocation';
const GENDER = 'sex';
const SPEED = 'speed'
(...)
}
我也作出了这是自动加载自定义配置文件tenkai_config.php
。在配置阵列我想使用常量从类作为密钥,即:
$config['vocations']['default'] = array(
'hero' => array(
Hero_attributes::LAST_LOGIN => 0,
Hero_attributes::LEVEL => 1,
Hero_attributes::MAG_LEVEL => 80,
Hero_attributes::RESIDENCE => 1,
Hero_attributes::POSITION_X => 73,
Hero_attributes::POSITION_Y => 181,
Hero_attributes::POSITION_Z => 6,
(...)
)
);
不过,我得到Fatal error: Class 'Hero_attributes' not found in C:\wamp_new\www\yourwodb\application\config\tenkai_config.php on line 29
消息。
如何在配置文件中使用常量?
它不会工作,因为config.php变量动态加载 – safarov 2012-04-01 18:21:43