我想创建一个用于站点配置的配置文件。我创建config.php
并将其放入Config
文件夹。这是它的内容:
<?php
Configure::write('Title', 'My App');
Configure::write('Categories', array(
'Recipes' =>
array('url' => '/recipe', 'max' => 10),
'Foods' =>
array('url' => '/food', 'max' => 5)
));
并将此代码放在bootstrap.php
:
Configure::load('config');
但是蛋糕会返回此错误:
No variable $config found in ...........\app\Config\config.php.php Error: An Internal Error Has Occurred. Stack Trace CORE\Cake\Core\Configure.php line 272 → PhpReader->read(string) APP\Config\bootstrap.php line 110 → Configure::load(string) CORE\Cake\Core\Configure.php line 92 → include(string) CORE\Cake\bootstrap.php line 142 → Configure::bootstrap(boolean) APP\webroot\index.php line 79 → include(string)
有什么问题?
注意:我使用的是最新版本:2.2.1稳定
答案 0 :(得分:4)
在配置文件中,如果要将$config
与默认的PhpReader一起使用,则应使用名为load()
的数组变量而不是Configure :: write。见API
实施例
<?php
$config = array(
'Title' => 'MyApp',
...
);
http://book.cakephp.org/2.0/en/development/configuration.html#built-in-configuration-readers