0

現在、ドクトリン 2 を codeigniter 2 に統合しようとしています。以下のチュートリアルに従って、これをすべて行っています。

http://www.joelverhagen.com/blog/2011/05/setting-up-codeigniter-2-with-doctrine-2-the-right-way/

私が持っていたチュートリアルによると

1)Doctrine 2 in  library
2)Doctrine.php file in  library
3)doctrine-cli.php in root folder
4)yaml file inside applications/models/mappings and also entities and proxies inside the same location

コマンドプロンプトからのチュートリアルによると、エンティティをユーザーエンティティとして作成しました

<?php

 namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * Entities\User
 */
class User
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $password
     */
    private $password;

    /**
     * @var string $firstName
     */
    private $firstName;

    /**
     * @var string $lastName
     */
    private $lastName;

    /**
     * @var string $email
     */
    private $email;

    /**
     * @var string $website
     */
    private $website;

    /**
     * @var datetime $created
     */
    private $created;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return User
     */
    public function setPassword($password)
    {
        $this->password = $password;
        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set firstName
     *
     * @param string $firstName
     * @return User
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
        return $this;
    }

    /**
     * Get firstName
     *
     * @return string 
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * Set lastName
     *
     * @param string $lastName
     * @return User
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
        return $this;
    }

    /**
     * Get lastName
     *
     * @return string 
     */
    public function getLastName()
    {
        return $this->lastName;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;
        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set website
     *
     * @param string $website
     * @return User
     */
    public function setWebsite($website)
    {
        $this->website = $website;
        return $this;
    }

    /**
     * Get website
     *
     * @return string 
     */
    public function getWebsite()
    {
        return $this->website;
    }

    /**
     * Set created
     *
     * @param datetime $created
     * @return User
     */
    public function setCreated($created)
    {
        $this->created = $created;
        return $this;
    }

    /**
     * Get created
     *
     * @return datetime 
     */
    public function getCreated()
    {
        return $this->created;
    }
}?>

記事の実体も

<?php

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * Entities\Article
 */
class Article
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $title
     */
    private $title;

    /**
     * @var text $content
     */
    private $content;

    /**
     * @var datetime $created
     */
    private $created;

    /**
     * @var Entities\User
     */
    private $user;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Article
     */
    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set content
     *
     * @param text $content
     * @return Article
     */
    public function setContent($content)
    {
        $this->content = $content;
        return $this;
    }

    /**
     * Get content
     *
     * @return text 
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * Set created
     *
     * @param datetime $created
     * @return Article
     */
    public function setCreated($created)
    {
        $this->created = $created;
        return $this;
    }

    /**
     * Get created
     *
     * @return datetime 
     */
    public function getCreated()
    {
        return $this->created;
    }

    /**
     * Set user
     *
     * @param Entities\User $user
     * @return Article
     */
    public function setUser(\Entities\User $user = null)
    {
        $this->user = $user;
        return $this;
    }

    /**
     * Get user
     *
     * @return Entities\User 
     */
    public function getUser()
    {
        return $this->user;
    }
}

そのチュートリアルで説明されているようにすべてのことを行いましたが、データベーステーブルに値を挿入しようとすると、エラーが発生しました

Fatal error: Class 'Entities' not found in D:\xampp\htdocs\ci_doctrine\application\controllers\welcome.php on line 32

ウェルカムコントローラーを使用してデータを挿入している間、コントローラーは

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */


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

      // $this->load->library('Doctrine.php');
        //$this->em = $this->doctrine->em;
    }

public function index()
{
    // create a new user object
    $user = new Entities/User;
    $user->setFirstName('Joel');
    $user->setLastName('Verhagen');
    $user->setPassword(md5('Emma Watson'));
    $user->setEmail('joel@joelverhagen.com');
    $user->setWebsite('http://www.joelverhagen.com');
    $user->setCreated(new DateTime());

    // standard way in CodeIgniter to access a library in a controller: $this->library_name->member->memberFunction()
    // save the object to database, so that it can obtain its ID
    $this->doctrine->em->persist($user);

    // create a new article object
    $article = new Entities/Article;
    $article->setTitle('Emma Watson is extremely talented, no?');
    $article->setContent('By talented, I mean good at lookin\' good.');
    $article->setCreated(new DateTime());
    // the user object you pass must be persisted first!
    $article->setUser($user);

    // save the article object to the database
    $this->doctrine->em->persist($article);
    $this->doctrine->em->flush();

    echo "<b>Success!</b>";

}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

何が起こっているのかわかりません....何か提案や助けが..??

4

1 に答える 1