cakePHP 中无法重新声明 config() 错误

发布于 2024-10-12 06:05:50 字数 239 浏览 6 评论 0原文

我收到错误 Fatal error: Cannot redeclare config() (之前在实时服务器中声明.../basics.php:58。它在我的本地服务器中工作正常,但是当我将网站上传到实时服务器时,我得到了致命错误。 我检查了 config() 是否已声明多次,但仅在 basics.php 文件中声明一次。 还遵循命名约定,因为它在本地服务器中运行良好。它仅在实时站点中显示此类错误。 请为此提出解决方案。

对此的帮助将不胜感激。

I am getting the error Fatal error: Cannot redeclare config() (previously declared in.../basics.php:58, in live server. It works fine in my local server but when i uploaded the site to live server, i got the fatal error.
I checked if the config() was declared multiple times but it's only declared once in basics.php file.
The naming conventions are also followed, as it is working fine in local server. It only displays such error in live site.
Please suggest solution for this.

Help on this will be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

拧巴小姐 2024-10-19 06:05:50

将 $uses 设置为 array() 并将 $autoRender 设置为 false 如下将解决此问题

   class IndexController extends AppController
    {

        public $uses = array();
        public $autoRender = false;

        public function index()
        {
            echo 'test';
        }

    }

set $uses to array() and $autoRender to false as follows will solve this problem

   class IndexController extends AppController
    {

        public $uses = array();
        public $autoRender = false;

        public function index()
        {
            echo 'test';
        }

    }
も星光 2024-10-19 06:05:50

我在运行 Apache 时遇到此错误,它最终与我的 .htaccess 文件被忽略有关 - 我一直在重新配置 Apache,并且不小心将 AllowOverride 设置为 我的配置文件中没有,这在某种程度上导致了此错误。

因此,简而言之,在您的 http.conf 或站点配置之一中,确保相关目录部分中的 AllowOverride 设置为 All(或 None 以外的其他内容) >),这是我的:

<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All 
    Order allow,deny
    allow from all
</Directory>

I had this error running Apache, and it ended up being related to my .htaccess files being ignored - I had been reconfiguring Apache, and had accidentally set AllowOverride to None in my config file, which was somehow causing this error.

So, in brief, in either your http.conf or one of your site configs, make sure the AllowOverride in your relevant Directory section is set to All (or something other than None), here's mine:

<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All 
    Order allow,deny
    allow from all
</Directory>
独闯女儿国 2024-10-19 06:05:50

如果多次包含“basics.php”,则可能会发生这种情况。您可以使用 include_once/require_once 而不是 include/require 来阻止它。

但这并不能解释为什么它可以在您的本地网络服务器上运行。

This can happen if "basics.php" was included multiple times. You can prevent it by using include_once/require_once instead of include/require.

But this doesn't explain why it's working on your local webserver.

迷路的信 2024-10-19 06:05:50

以防万一有人碰巧搜索这个。

我在安装了 cakephp 1.3.11 的 Windows 2003 服务器上遇到了同样的错误。就我而言,这是因为我在一个类关联声明中出现了拼写错误。

我定义了一个 Client 类,其中包含与 Account 类的 hasOne 关联。我错误地向 Client 输入了 className 属性,这创建了一个循环,并导致了 cakePHP 中的 Cannot redeclare config() 错误

Just in case somebody happens to search for this.

I had the same error on a windows 2003 server with cakephp 1.3.11 installed. In my case it was because I had a typo in one class association declaration.

I had defined a Client class with a hasOne association to a Account class. There I had wrongly typed the className property to Client which created a loop and resulted in the Cannot redeclare config() error in cakePHP.

没有伤那来痛 2024-10-19 06:05:50

检查您的 PHP 版本。当您使用比 5.3 更严格的 PHP 版本 5.4 时,会发生该错误,

打开 cake/bootstrap.php 并进行更改以确保使用函数“require_once”加载每个文件一次。代码将是这样的:

require_once CORE_PATH . 'cake' . DS . 'basics.php';
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require_once LIBS . 'object.php';
require_once LIBS . 'inflector.php';
require_once LIBS . 'configure.php';
require_once LIBS . 'set.php';
require_once LIBS . 'cache.php';
Configure::getInstance();
require_once CAKE . 'dispatcher.php';

Check your PHP version. that errors happens when you use PHP version 5.4 which is more stricter than 5.3

open your cake/bootstrap.php and make changes to make sure every file loaded once with function 'require_once'. The code will be like this:

require_once CORE_PATH . 'cake' . DS . 'basics.php';
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require_once LIBS . 'object.php';
require_once LIBS . 'inflector.php';
require_once LIBS . 'configure.php';
require_once LIBS . 'set.php';
require_once LIBS . 'cache.php';
Configure::getInstance();
require_once CAKE . 'dispatcher.php';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文