Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine2: ReflectionException' with message 'Class Comment does not exist in ...' while trying use doctrine models in codeigniter controller
    primarykey
    data
    text
    <p>I got "Message: class_parents(): Class Comment does not exist and could not be loaded" while trying to use Doctrine models in CodeIgniter controller.</p> <p>Here is full stacktrace Fatal error: Uncaught exception 'ReflectionException' with message 'Class Comment does not exist' in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php:73 Stack trace: #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 on line 73</p> <p>Here is my model in /application/models/Entities/Comment.php</p> <pre><code> &lt;?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-&gt;id; } /** * Set parentid * * @param integer $parentid * @return Comment */ public function setParentid($parentid) { $this-&gt;parentid = $parentid; return $this; } /** * Get parentid * * @return integer */ public function getParentid() { return $this-&gt;parentid; } /** * Set isactive * * @param integer $isactive * @return Comment */ public function setIsactive($isactive) { $this-&gt;isactive = $isactive; return $this; } /** * Get isactive * * @return integer */ public function getIsactive() { return $this-&gt;isactive; } /** * Set isremoved * * @param integer $isremoved * @return Comment */ public function setIsremoved($isremoved) { $this-&gt;isremoved = $isremoved; return $this; } /** * Get isremoved * * @return integer */ public function getIsremoved() { return $this-&gt;isremoved; } /** * Set removaldate * * @param datetime $removaldate * @return Comment */ public function setRemovaldate($removaldate) { $this-&gt;removaldate = $removaldate; return $this; } /** * Get removaldate * * @return datetime */ public function getRemovaldate() { return $this-&gt;removaldate; } /** * Set user_name * * @param string $userName * @return Comment */ public function setUserName($userName) { $this-&gt;user_name = $userName; return $this; } /** * Get user_name * * @return string */ public function getUserName() { return $this-&gt;user_name; } /** * Set user_email * * @param string $userEmail * @return Comment */ public function setUserEmail($userEmail) { $this-&gt;user_email = $userEmail; return $this; } /** * Get user_email * * @return string */ public function getUserEmail() { return $this-&gt;user_email; } /** * Set user_avatar * * @param string $userAvatar * @return Comment */ public function setUserAvatar($userAvatar) { $this-&gt;user_avatar = $userAvatar; return $this; } /** * Get user_avatar * * @return string */ public function getUserAvatar() { return $this-&gt;user_avatar; } /** * Set comment * * @param text $comment * @return Comment */ public function setComment($comment) { $this-&gt;comment = $comment; return $this; } /** * Get comment * * @return text */ public function getComment() { return $this-&gt;comment; } /** * Set creationdate * * @param datetime $creationdate * @return Comment */ public function setCreationdate($creationdate) { $this-&gt;creationdate = $creationdate; return $this; } /** * Get creationdate * * @return datetime */ public function getCreationdate() { return $this-&gt;creationdate; } /** * Set rating * * @param integer $rating * @return Comment */ public function setRating($rating) { $this-&gt;rating = $rating; return $this; } /** * Get rating * * @return integer */ public function getRating() { return $this-&gt;rating; } } </code></pre> <p>And here is controller's code </p> <pre><code>&lt;?php require APPPATH . 'models\Entities\Comment.php'; class CommentController extends CI_Controller{ var $em; function __construct() { parent::__construct(); $this-&gt;em = $this-&gt;doctrine-&gt;em; } public function index() { $comment = $this-&gt;em-&gt;find('Comment', 1); echo $comment-&gt;user_name . '&lt;br/&gt;' . $comment-&gt;comment; } } </code></pre> <p>Here is doctrine.php</p> <pre><code>&lt;?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-&gt;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-&gt;register(); // load the entities $entityClassLoader = new \Doctrine\Common\ClassLoader('Entities', APPPATH.'models'); $entityClassLoader-&gt;register(); // load the proxy entities $proxyClassLoader = new \Doctrine\Common\ClassLoader('Proxies', APPPATH.'models'); $proxyClassLoader-&gt;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-&gt;setMetadataCacheImpl($cache); $config-&gt;setQueryCacheImpl($cache); // set up proxy configuration $config-&gt;setProxyDir(APPPATH.'models/Proxies'); $config-&gt;setProxyNamespace('Proxies'); // auto-generate proxy classes if we are in development mode $config-&gt;setAutoGenerateProxyClasses(ENVIRONMENT == 'development'); // set up annotation driver $yamlDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(APPPATH.'models\Mappings'); $config-&gt;setMetadataDriverImpl($yamlDriver); // Database connection information $connectionOptions = array( 'driver' =&gt; 'pdo_mysql', 'user' =&gt; $db['default']['username'], 'password' =&gt; $db['default']['password'], 'host' =&gt; $db['default']['hostname'], 'dbname' =&gt; $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-&gt;em = $em; } } </code></pre> <p>CAN'T FIND OUT WHAT IS GOING WRONG. I'm quite newbie on php and it's technologies. Please help. Any useful ideas will be appreciated</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload