Closed dsoms closed 9 years ago
Hello @dsoms
One things, is the error, it seems the annotation is not loadable. There are to common reasons for this. First the annotation class is not available (did you installed symfony/validatior), the second the annotation registry is missing.
To get annotation validation running you need something like this:
https://github.com/saxulum/saxulum-validator-provider
Regards @dominikzogg
Hello @dominikzogg
1- symfony/validatior is installed
composer.json
{
"name": "fabpot/silex-skeleton",
"description": "A pre-configured skeleton for the Silex microframework",
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.3.3",
"silex/silex": "~1.0",
"silex/web-profiler": "~1.0",
"symfony/browser-kit": "~2.3",
"symfony/class-loader": "~2.3",
"symfony/config": "~2.3",
"symfony/console": "~2.3",
"symfony/css-selector": "~2.3",
"symfony/debug": "~2.3",
"symfony/finder": "~2.3",
"symfony/form": "~2.3",
"symfony/monolog-bridge": "~2.3",
"symfony/process": "~2.3",
"symfony/security": "~2.3",
"symfony/translation": "~2.3",
"symfony/twig-bridge": "~2.3",
"symfony/validator": "~2.3",
"doctrine/dbal": "2.*",
"symfony/doctrine-bridge": "2.*",
"dflydev/doctrine-orm-service-provider": "1.0.*@dev"
},
"autoload": {
"psr-0": { "": "src/" }
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
}
}
2- I think the annotation registry is missing. I installed Silex with "fabpot/silex-skeleton". Which file I have to put this code?
<?php
$loader = require __DIR__ . '/../vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
3- I can't install saxulum-validator-provider, my Pimple version is 1.1.1 and is required >=2.1,<4
Regards @dsoms
Hello @dsoms
Adding the registry after require the $loader
is perfect.
Use the version ~1.0 of my validator, its for silex ~1.0
Regards dominikzogg
If you really want to use the allready loaded doctrine bridge, take a look at: https://github.com/saxulum/saxulum-doctrine-orm-manager-registry-provider use the v2 its for silex ~1.0
Hi @dominikzogg
If I install the version ~1.0 of your validator, then also need the above code or I need the both?
<?php
$loader = require __DIR__ . '/../vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
Regards @dsoms
@dsoms yes
@dsoms you need it only ones, not ones foreach annotation using lib
Hi @dominikzogg
It works! Thank you very much for your help!
Finally I put the code in the file "src/app.php".
Regards @dsoms
@dsoms your welcome, would be cool if you close the issue
@dominikzogg One more thing, if I like to have UniqueEntity Constraint Support within Symfony Validator Component, I need to install saxulum-doctrine-orm-manager-registry-provider and saxulum-validator-provider or only the first one?
@dsoms you need both
Hi @dominikzogg
It works too! Again, thank you very much for your help!
Issue closed.
Regards @dsoms
Hi!
I am trying to use vahlidation annotations in a Doctrine entity, but when I want to generate entities it fails. If I remove the validation annotations the entity and repository are generated correctly.
May be an config issue? Or isn't possible to use validation annotations in a Doctrine entity with Silex?
Thank you!
This is the code/configuration/output:
Entity with validation annotations
Doctrine ORM configuration
Console command
Output