Я запустил новый проект и хотел использовать Doctrine 2 в Zend Framework (1.11).
Я сконфигурировал все в Bootstrap & Config, что вроде бы хорошо.
Здесьмоя первая модель, которую я создал для использования:
<?php
namespace Entities;
/**
* @Entity
* @Table(name="posts")
*/
class Post
{
/** @Id @Column(type="integer") @GeneratedValue */
public $id;
/** @Column(length=100,nullable=true) */
public $title;
/** @Column(length=2000) */
public $message;
/** @Column(type="integer") */
public $userId;
/** @Column(type="timestamp") */
public $dateAdded;
}
А вот контроллер:
<?php
class CityController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$em = Zend_Registry::get('em');
$group = $em->find('Entities\Post', 1);
}
}
Когда я пытаюсь получить доступ к модели Entities\Post
, он просто выдает ошибку, говоря, чтоэто не существуетЯ уверен, что это проблема соглашения об именах Zend, но я попробовал несколько разных вещей, но ничего не помогло.
Есть идеи?И я просмотрел все учебные пособия по Doctrine 2 / Zend, которые смог найти, и ни одно из них не сильно помогло.
* ОБНОВЛЕНИЕ *
Вот мой инициат Учения вbootstrap:
public function _initDoctrine() {
// include and register Doctrine's class loader
require_once('Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine',
APPLICATION_PATH . '/../library/'
);
$classLoader->register();
// create the Doctrine configuration
$config = new \Doctrine\ORM\Configuration();
// setting the cache ( to ArrayCache. Take a look at
// the Doctrine manual for different options ! )
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// choosing the driver for our database schema
// we'll use annotations
$driver = $config->newDefaultAnnotationDriver(
APPLICATION_PATH . '/models'
);
$config->setMetadataDriverImpl($driver);
// set the proxy dir and set some options
$config->setProxyDir(APPLICATION_PATH . '/models/Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setProxyNamespace('App\Proxies');
// now create the entity manager and use the connection
// settings we defined in our application.ini
$connectionSettings = $this->getOption('doctrine');
$conn = array(
'driver' => $connectionSettings['conn']['driv'],
'user' => $connectionSettings['conn']['user'],
'password' => $connectionSettings['conn']['pass'],
'dbname' => $connectionSettings['conn']['dbname'],
'host' => $connectionSettings['conn']['host']
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// push the entity manager into our registry for later use
$registry = Zend_Registry::getInstance();
$registry->em = $entityManager;
return $entityManager;
}
А вот конфиг для доктрины (в application.ini):
doctrine.conn.host = 'localhost'
doctrine.conn.user = '****'
doctrine.conn.pass = '****'
doctrine.conn.driv = 'pdo_mysql'
doctrine.conn.dbname = '****'
doctrine.path.models = APPLICATION_PATH "/models"
Как видите, он ищет модели в APPLICATION_PATH "/models"