Need help creating Doctrine 2

i setup Doctrine 1 b4, but it seems that now when I try to execute Doctrine 2, it fails

I have a doctrine 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\binin the PATHwindows environment variable and added D:\ResourceLibrary\Frameworks\Doctrineto php.iniinclude_path

I find that when I try to do

D:\>php doctrine.php
Could not open input file: doctrine.php

you can not ... I think that, as I have D:\ResourceLibrary\Frameworks\Doctrine\binin the PATHWindows environment variables, they can be found 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 try, skip with errors ...

+3
source share
4 answers

You do not need the entire Symfony infrastructure. Just the beat that the Doctrine rests on.

ORM ( BETA2), Symfony ( , lib/vendor/Symfony, ). , ClassLoader doctrine.php cli-config.php Symfony.

$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . '/path/to/Symfony');
$classLoader->register();

, . Doctrine , .

+3

, Doctrine 2 , , , Doctrine 2.

Doctrine 2 .

Doctrine 2, .

DoctrineORM-2.0.0BETA3.tgz http://www.doctrine-project.org/projects/orm/download

tar , .

./test
DoctrineORM/
DoctrineORM/bin
DoctrineORM/bin/Doctrine

2 "" "".

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 ---

--- 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 ---

.

./test
DoctrineORM/
DoctrineORM/bin
DoctrineORM/bin/Doctrine

Model/
Model/User.php
test.php

, . , , .

+6

- Doctrine 2, Symfony 2 ( ) include.

As far as I know, there is currently no PEAR installation, so you have to download sources from the Symfony 2 site or through Git.

On the side: It seems that you also tried to execute doctrine.php along a path where it does not exist. That's why you got

Failed to open input file: doctrine.php

error message.

0
source

Doctrine v2. * stored in the bin directory.

Try it like this:

$ vendor/bin/doctrine orm:conver-mapping xml src/ --from-database --force

Do not run PHP at startup.

0
source

Source: https://habr.com/ru/post/1754817/


All Articles