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');

但是 cake 返回这个错误:

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 Stable

4

1 回答 1

4

$config在你的配置文件中,如果你想使用load()默认的 PhpReader,你应该使用一个名为而不是 Configure::write 的数组变量。见API

前任。

<?php
$config = array(
    'Title' => 'MyApp',
    ...
);

http://book.cakephp.org/2.0/en/development/configuration.html#built-in-configuration-readers

于 2012-07-18T15:56:07.117 回答