I know exactly same type of issue has been posted here many times. But not a single one solved my problem, really frustrated ,googling for more than 2 days finding solutions still with no success. I am stucked here not able to proceed ahead with my project. I have stated solutions I found through google in the last which didn't solve my problem.
Here are my specs: Using Zend Framework 2.1.5 with doctrineORMModule on wamp server / php 5.4.3 / apache 2.2.22.
Here are my doctrine configurations in Application/config/module.config.php
// Doctrine Configurations
'doctrine' => array(
'driver' => array(
// defines an annotation driver with two paths, and names it `my_annotation_driver`
'my_annotation_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Application/Model',
),
),
// default metadata driver, aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing
'orm_default' => array(
'drivers' => array(
// register `my_annotation_driver` for any entity under namespace `My\Namespace`
'Application\Model' => 'my_annotation_driver'
)
)
)
),
// End doctrine configurations
User Entity class in Application/src/Application/Model/User.php
namespace Application\Model;
/*
* @Entity
* @Table(name="user")
*/
class User
{
/*
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/*
* @Column(type="string")
*/
private $username;
/*
* @Column(type="string")
*/
private $password;
/*
* @Column(type="string")
*/
private $email;
/*
* @Column(type="string")
*/
private $name;
/*
* @Column(type="string")
*/
private $profile_pic;
/*
* @Column(type="string")
*/
private $cover_pic;
/*
* @Column(type="integer")
*/
private $status;
/*
* @Column(type="datetime")
*/
private $created_at;
public function getUsername()
{
return $this->username;
}
}
UserController in Application/src/Application/Controller/UserController.php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class UserController extends AbstractActionController
{
public function IndexAction()
{
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$user = $em->find('Application\Model\User', 1);
var_dump($user);
exit;
}
}
Url - public/application/user -> throws exception ,below is the stak trace and error
Doctrine\ORM\Mapping\MappingException
File:
C:\wamp\library\Doctrine\ORM\Mapping\MappingException.php:216
Message:
Class "Application\Model\User" is not a valid entity or mapped super class.
Stack trace:
0 C:\wamp\library\Doctrine\ORM\Mapping\Driver\AnnotationDriver.php(87): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('Application\Mod...')
1 C:\wamp\library\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php(104): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('Application\Mod...', Object(Doctrine\ORM\Mapping\ClassMetadata))
2 C:\wamp\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php(113): Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain- >loadMetadataForClass('Application\Mod...', Object(Doctrine\ORM\Mapping\ClassMetadata))
3 C:\wamp\library\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(302): Doctrine\ORM\Mapping\ClassMetadataFactory- >doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array)
4 C:\wamp\library\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(205): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory- >loadMetadata('Application\Mod...')
5 C:\wamp\library\Doctrine\ORM\EntityManager.php(268): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Application\Mod...')
6 C:\wamp\library\Doctrine\ORM\EntityManager.php(682): Doctrine\ORM\EntityManager->getClassMetadata('Application\Mod...')
7 C:\wamp\www\indians\module\Application\src\Application\Controller\UserController.php(23): Doctrine\ORM\EntityManager->getRepository('Application\Mod...')
8 C:\wamp\library\Zend\Mvc\Controller\AbstractActionController.php(83): Application\Controller\UserController->IndexAction()
9 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
10 C:\wamp\library\Zend\EventManager\EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
11 C:\wamp\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
12 C:\wamp\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
13 C:\wamp\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
14 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
15 C:\wamp\library\Zend\EventManager\EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
16 C:\wamp\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
17 C:\wamp\library\Zend\Mvc\Application.php(294): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
18 C:\wamp\www\indians\public\index.php(12): Zend\Mvc\Application->run()
19 {main}
Solutions I found:
- turning off eaccelerator (eaccelrator is not installed on my wamp server, So this is not an issue)
- change annotation mapping @Entity to @ORM\Entity (checked using both ,didn't solve my problem- seems like
$config->newDefaultAnnotationDriver($path, true)
second paramsimpleannotationreader
is set to true.So it will read simple annotation ex.@Entity
though I checked by using@ORM\Entity
still doesn't work) - Some Place I found that I should call
annotationRegistry::somemethod()
if this is the solution then which method I shud call fromannotationRegistry
class and where's the exact place to call.
cmd commands:
./vendor/bin/doctrine-module orm:validate-schema
shows no error '[Mapping] OK - The mapping files are correct. [Database] OK - The database schema is sync with the mapping files.'- however executing this command -
`./vendor/bin/doctrine-module orm:info
throws exception as follows 'You do not have any mapped orm entities according to the current configuration. I you have entities or mapping files you should check your mapping configuration for errors.'
That's it .Now all I can do is keep my hope and patience. thanks for checking out my issue.
use Doctrine\ORM\Mapping as ORM
=>@ORM\*
. Furthermore, when validating schemata via the commandline, always make sure to delete the frikkin cache (when youre on windows) ;) – SamApplication\Model\User
resolves correctly to the class. As much I know entitymanager just needs an entity class with proper annotations. – Sumeetuse Doctrine\ORM\Mapping as ORM;
at the top of your Model's class file, and converted all your annotations to have theORM` prefix (so
@Entity` becomes@ORM\Entity
, etc, for every annotation)? – timdev