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