3
我想创建一个用于站点配置的配置文件。我创建了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稳定
感谢,如果我想使用'配置:: write'其功能需要?我应该把'config :: config('config')'?一般来说,在Cake中配置应用程序配置文件的最佳和标准方法是什么? – mrdaliri 2012-07-18 15:59:36
这就是'bootstrap.php'的用途。如果你想在一个单独的文件中,可能只是在'bootstrap.php'中使用'include config.php'将会是最简单的。我不确定另一种方式。 – tigrang 2012-07-18 16:06:10
确切地说 - 使用数组加载()并且使用Configure :: write()包含/ require – mark 2012-07-18 16:09:55