1

CodeIgniter コントローラで Doctrine モデルを使用しようとしているときに、「メッセージ: class_parents(): クラス コメントが存在しないため、ロードできませんでした」というメッセージが表示されました。

ここに完全なスタックトレースがあります 致命的なエラー: C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php にメッセージ「Class Comment does not exist」を含む例外「ReflectionException」がキャッチされていません:73 スタック トレース: #0 C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(73): ReflectionClass->__construct('Comment') #1 C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\Mapping\ClassMetadataInfo.php(769): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getClass('Comment') #2 C :\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php(591): Doctrine\ORM\Mapping\ClassMetadataInfo->initializeReflection(Object(Doctrine\Common\Persistence\Mapping\RuntimeReflectionService)) #3 C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php(272): Doctrine\ORM \Mapping\ClassMetadataFactory->initializ in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php 行 73

これが /application/models/Entities/Comment.php の私のモデルです

    <?php

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

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

    /**
     * @var integer $parentid
     */
    private $parentid;

    /**
     * @var integer $isactive
     */
    private $isactive;

    /**
     * @var integer $isremoved
     */
    private $isremoved;

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

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

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

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

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

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

    /**
     * @var integer $rating
     */
    private $rating;


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

    /**
     * Set parentid
     *
     * @param integer $parentid
     * @return Comment
     */
    public function setParentid($parentid)
    {
        $this->parentid = $parentid;
        return $this;
    }

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

    /**
     * Set isactive
     *
     * @param integer $isactive
     * @return Comment
     */
    public function setIsactive($isactive)
    {
        $this->isactive = $isactive;
        return $this;
    }

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

    /**
     * Set isremoved
     *
     * @param integer $isremoved
     * @return Comment
     */
    public function setIsremoved($isremoved)
    {
        $this->isremoved = $isremoved;
        return $this;
    }

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

    /**
     * Set removaldate
     *
     * @param datetime $removaldate
     * @return Comment
     */
    public function setRemovaldate($removaldate)
    {
        $this->removaldate = $removaldate;
        return $this;
    }

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

    /**
     * Set user_name
     *
     * @param string $userName
     * @return Comment
     */
    public function setUserName($userName)
    {
        $this->user_name = $userName;
        return $this;
    }

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

    /**
     * Set user_email
     *
     * @param string $userEmail
     * @return Comment
     */
    public function setUserEmail($userEmail)
    {
        $this->user_email = $userEmail;
        return $this;
    }

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

    /**
     * Set user_avatar
     *
     * @param string $userAvatar
     * @return Comment
     */
    public function setUserAvatar($userAvatar)
    {
        $this->user_avatar = $userAvatar;
        return $this;
    }

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

    /**
     * Set comment
     *
     * @param text $comment
     * @return Comment
     */
    public function setComment($comment)
    {
        $this->comment = $comment;
        return $this;
    }

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

    /**
     * Set creationdate
     *
     * @param datetime $creationdate
     * @return Comment
     */
    public function setCreationdate($creationdate)
    {
        $this->creationdate = $creationdate;
        return $this;
    }

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

    /**
     * Set rating
     *
     * @param integer $rating
     * @return Comment
     */
    public function setRating($rating)
    {
        $this->rating = $rating;
        return $this;
    }

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

そして、ここにコントローラーのコードがあります

<?php
require APPPATH . 'models\Entities\Comment.php';

class CommentController extends CI_Controller{
    var $em;
    function __construct() {
        parent::__construct();
        $this->em = $this->doctrine->em;
    }
    public function index()
    {
        $comment = $this->em->find('Comment', 1);
        echo $comment->user_name . '<br/>' . $comment->comment;
    }
}

これがdoctrine.phpです

<?php


class Doctrine
{
    // the Doctrine entity manager
    public $em = null;

    public function __construct()
    {
        // include our CodeIgniter application's database configuration
        require_once APPPATH.'config/database.php';

        // include Doctrine's fancy ClassLoader class
        require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';

        // load the Doctrine classes
        $doctrineClassLoader = new \Doctrine\Common\ClassLoader('Doctrine', APPPATH.'libraries');
        $doctrineClassLoader->register();

        // load Symfony2 helpers
        // Don't be alarmed, this is necessary for YAML mapping files
        $symfonyClassLoader = new \Doctrine\Common\ClassLoader('Symfony', APPPATH.'libraries/Doctrine');
        $symfonyClassLoader->register();

        // load the entities
        $entityClassLoader = new \Doctrine\Common\ClassLoader('Entities', APPPATH.'models');
        $entityClassLoader->register();

        // load the proxy entities
        $proxyClassLoader = new \Doctrine\Common\ClassLoader('Proxies', APPPATH.'models');
        $proxyClassLoader->register();

        // set up the configuration
        $config = new \Doctrine\ORM\Configuration;

        if(ENVIRONMENT == 'development')
            // set up simple array caching for development mode
            $cache = new \Doctrine\Common\Cache\ArrayCache;
        else
            // set up caching with APC for production mode
            $cache = new \Doctrine\Common\Cache\ApcCache;
        $config->setMetadataCacheImpl($cache);
        $config->setQueryCacheImpl($cache);

        // set up proxy configuration
        $config->setProxyDir(APPPATH.'models/Proxies');
        $config->setProxyNamespace('Proxies');

        // auto-generate proxy classes if we are in development mode
        $config->setAutoGenerateProxyClasses(ENVIRONMENT == 'development');

        // set up annotation driver
        $yamlDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(APPPATH.'models\Mappings');
        $config->setMetadataDriverImpl($yamlDriver);

        // Database connection information
        $connectionOptions = array(
            'driver' => 'pdo_mysql',
            'user' => $db['default']['username'],
            'password' => $db['default']['password'],
            'host' => $db['default']['hostname'],
            'dbname' => $db['default']['database']
        );

        // create the EntityManager
        $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

        // store it as a member, for use in our CodeIgniter controllers.
        $this->em = $em;
    }
}

何が間違っているのかわかりません。私はPHPの初心者であり、それはテクノロジーです。助けてください。有用なアイデアは高く評価されます

4

1 に答える 1

6

文字列では、常に完全修飾クラス名を使用します。

この行はから変更する必要があります

$comment = $this->em->find('Comment', 1);

$comment = $this->em->find('Entities\Comment', 1);
于 2013-02-27T10:00:34.803 に答える