简体   繁体   中英

CodeIgniter Fatal error: Cannot redeclare class

I'm getting the error:

Fatal error: Cannot redeclare class News in application\\models\\Entities\\News.php

The two classes are as follow:

application/models/News_model.php

<?php
require_once(APPPATH."models/Entities/News.php");

class News_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }
}

application/models/Entities/News.php

<?php
use Doctrine\ORM\Mapping as ORM;

/**
* News
*
* @ORM\Table(name="news", indexes={@ORM\Index(name="slug", columns {"slug"})})
* @ORM\Entity
*/
class News {
}

The first class is a model and the last class is entity class for Doctrine .

I cannot see which is the conflict whether the two names are different.

I'm using CodeIgniter 3.1.4 .

Anyone has an idea how to solve this issue?

Thanks in advanced!

You have 2 classes with the same name.

The file being included with require_once is called News.php, therefor I assume it is a class called News.

Then you also have a News class in Doctrine. There 2 classes are in the same namespace with the same name and php does not allow that. You will either need to look into using namespaces or change the name of one of those 2 classes.

Note that it is not your model itself in codeigniter but the file being included by using require once which is conflicting with your Doctrine News class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM