Need help setting up Doctrine 2
i setup Doctrine 1 b4 but it seems like now when i try Doctrine 2 it fails
i have Doctrine installed at D:\ResourceLibrary\Frameworks\Doctrine
D:\ResourceLibrary\Frameworks\Doctrine\bin
D:\ResourceLibrary\Frameworks\Doctrine\Doctrine
D:\ResourceLibrary\Frameworks\Doctrine\Doctrine\Common
D:\ResourceLibrary\Frameworks\Doctrine\Doctrine\DBAL
D:\ResourceLibrary\Frameworks\Doctrine\Doctrine\ORM
i put D:\ResourceLibrary\Frameworks\Doctrine\bin
开发者_StackOverflow中文版 in the PATH
Windows Environment Variable
and added D:\ResourceLibrary\Frameworks\Doctrine
to the php.ini include_path
i find that when i try to do
D:\>php doctrine.php
Could not open input file: doctrine.php
fails ... i thought that since i have D:\ResourceLibrary\Frameworks\Doctrine\bin
in the PATH
Windows Environment Variable, it shld be able to find doctrine.php
?
D:\ResourceLibrary\Frameworks\Doctrine\bin>php doctrine.php
Warning: require(D:\ResourceLibrary\Frameworks\Doctrine\bin/../lib/vendor\Symfony\Components\Console\Helper\HelperSet.ph
p): failed to open stream: No such file or directory in D:\ResourceLibrary\Frameworks\Doctrine\Doctrine\Common\ClassLoad
er.php on line 143
Fatal error: require(): Failed opening required 'D:\ResourceLibrary\Frameworks\Doctrine\bin/../lib/vendor\Symfony\Compon
ents\Console\Helper\HelperSet.php' (include_path='D:\ResourceLibrary\Frameworks\ZendFramework\library;D:\ResourceLibrary
\Frameworks\Doctrine;.;c:\php\includes') in D:\ResourceLibrary\Frameworks\Doctrine\Doctrine\Common\ClassLoader.php on li
ne 143
then 2nd try, pass with errors ...
After spending several hours to configure Doctrine 2 on my machine last night I finally succedded to work with Doctrine 2.
I configured Doctrine 2 in this way.
There are several ways to install Doctrine 2 although I preferred to download from package manager.
First I downloaded package DoctrineORM-2.0.0BETA3.tgz from http://www.doctrine-project.org/projects/orm/download
I extracted the tar file inside my test folder where I tested my sample code. My folder looks like
./test
DoctrineORM/
DoctrineORM/bin
DoctrineORM/bin/Doctrine
Then I created 2 folders on root 'model' and 'proxies'.
Now we need to bootstrap Doctrine.
--- Bootsrap ---
<?php
// test.php
require 'DoctrineORM/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'DoctrineORM');
$classLoader->register(); // register on SPL autoload stack
$classloader = new \Doctrine\Common\ClassLoader('model', __DIR__);
$classloader->register();
$config = new \Doctrine\ORM\Configuration();
$cache = new \Doctrine\Common\Cache\ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('model');
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir('proxies');
$config->setProxyNamespace('proxies');
$config->setAutoGenerateProxyClasses(true);
$config->getAutoGenerateProxyClasses();
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'test',
'user' => '[DB_User]',
'password' => '[DB_Pass]'
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
//echo 'Hello World!' . PHP_EOL;
// Get result from Table
$q = $em->createQuery('SELECT c FROM model\User c ORDER BY c.name');
$t = $q->getResult();
echo "<pre>"; print_r($t);
// Save a new User to DB
$uu = new model\User();
$uu->name = 'test name1';
$uu->age = 4;
$em->persist($uu);
$em->flush();
--- Bootsrap ---
Then I created a model file in model directory
--- Model - User.php ---
<?php
// Model File model/User.php
namespace Model;
/** @Entity @Table(name="users") */
class User
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/** @Column(type="string", length=50) */
public $name;
/** @Column(type="integer", length=50) */
public $age;
}
--- Model - User.php ---
My complete folder structure now looks like below.
./test
DoctrineORM/
DoctrineORM/bin
DoctrineORM/bin/Doctrine
Model/
Model/User.php
test.php
Hope this will help you. If you need any further help I can send you the complete source which works fine at my machine.
You don't need the entire Symfony framework. Just the bits that Doctrine relies on.
If you download the current version of the ORM component (right now at BETA2), it will include a folder called Symfony
(probably in lib/vendor/Symfony
, but it tends to move around with new releases). You need to make sure that the ClassLoader in doctrine.php
or cli-config.php
can find that Symfony folder.
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . '/path/to/Symfony');
$classLoader->register();
I hope this information is accurate. The Doctrine team keeps messing with the structure of the release they closer they get to a final version.
If you want to use the command line interface in the new Doctrine 2 beta you also have to install the Symfony 2 framework (because it includes the Console Helper) and put it into your include path.
As far as I know there is currently no PEAR installation available, so you will have to download the sources from the Symfony 2 website or via Git.
On a sidenote: It seems that you also tried to execute doctrine.php at a path where it doesn’t exist. That’s the reason why you got the
Could not open input file: doctrine.php
error message.
Doctrine v2.* is stored in bin dir.
Try like this :
$ vendor/bin/doctrine orm:conver-mapping xml src/ --from-database --force
Dont put PHP on start.
精彩评论