When using Composer, you can configure your namespaces in the `autoload` in
your `composer.json`:
"autoload": {
"psr-0": {
"MyProject": "src/"
}
}
This way you won't have to edit the `autoload_namespaces.php` everytime it's
regenerated.
Secondly, this autoloader follows the PSR-0 standard [1].
This basically means that when have the class `MyClass` in the namespace
`MyProject`, so the Fully Qualified NameSpace (FQNS) is `MyClass\MyProject`,
that class must exist in the file `src/MyProject/MyClass.php`.
In other words, the namespace relates to the path, the class to the filename.
[1]: http://www.php-fig.org/psr/psr-0/
--
Jasper N. Brouwer
(@jaspernbrouwer)
On 29 July 2014 at 13:39:32, Jordi Martínez ([email protected]) wrote:
> Hello,
>
> I'm beginning with Doctrine. I've installed it into my project, I've
> created some classes (without namespace) with its mapping configurations
> and it works fine :-)
>
> But when I try to define the namespace for some of this classes Doctrine
> can't find it :-(
>
>
> When I add namespace I do this:
>
> //MyClass.php
>
> > namespace MyProject;
>
>
> class MyClass
> { ...
>
>
> //MyController.php
>
> use Doctrine\ORM\Tools\Setup;
> use Doctrine\ORM\EntityManager;
>
>
> require_once "uicmodel/vendor/autoload.php";
>
>
> $config = Setup::createYAMLMetadataConfiguration(array(__DIR__.
> "/../doctrine_config/yaml"), true);
>
>
> // database configuration parameters
> $con = array(
> 'dbname' => 'db',
> 'user' => 'myuser',
> 'password' => '',
> 'driver' => 'pdo_pgsql',
> 'host' => 'my-host.com'
> );
>
>
> // obtaining the entity manager
> $EntityManager = EntityManager::create($con, $config);
> $EntityRepository = $EntityManager->getRepository('MyProject/MyClass');
>
>
> Even I've tried to modify MyProject/vendor/composer/autoload_namespaces.php
> to register this namespace:
> > // autoload_namespaces.php @generated by Composer
> $vendorDir = dirname(dirname(__FILE__));
> $baseDir = dirname($vendorDir);
> return array(
> 'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
> 'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'
> ),
> 'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
> 'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'),
> 'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'
> ),
> 'Doctrine\\Common\\Inflector\\' => array($vendorDir .
> '/doctrine/inflector/lib'),
> 'Doctrine\\Common\\Collections\\' => array($vendorDir .
> '/doctrine/collections/lib'),
> 'Doctrine\\Common\\Cache\\' => array($vendorDir . '/doctrine/cache/lib'
> ),
> 'Doctrine\\Common\\Annotations\\' => array($vendorDir .
> '/doctrine/annotations/lib'),
> 'Doctrine\\Common\\' => array($vendorDir . '/doctrine/common/lib'),
> 'MyProject\\' => array($baseDir . '/src'),
> );
>
>
> Modifying (or not doing) autoload Doctrine laugh an Exception saying it
> can't find class MyClass :-(
>
> Any idea? I've searched for long and I can't doing work :-S
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.