Заметка Люди отметили этот вопрос как похожий на других, но его нет = - Я не использую symfony и doctrine как веб-фреймворк, я использую компоненты symfony с доктриной, используя Slimphp в качестве фактического веб-рамки.PHP AppKernel Symfony Issue
Так что, хотя вы можете подумать, что мне нужен AppKernel
, я этого не делаю. Я использую компоненты symfony. Единственная проблема в том, что @UniqueEntity
не работает.
Я понятия не имею, что я делаю. Я получаю сообщение об ошибке:
Fatal error: Class 'doctrine.orm.validator.unique' not found in /var/www/html/image_upload_app/vendor/symfony/validator/ConstraintValidatorFactory.php on line 46
Мои AppKernel.php
выглядит следующим образом:
namespace ImageUploader;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel {
public function registerBundles() {
$bundles = array(
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle()
);
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader) {}
}
Оттуда я создал bootstrap.php
со следующим содержанием:
/** ---------------------------------------------------------------- **/
// Lets Setup Doctrine.
/** ---------------------------------------------------------------- **/
require_once 'vendor/autoload.php';
$loader = require 'vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
/**
* Set up Doctrine.
*/
class DoctrineSetup {
/**
* @var array $paths - where the entities live.
*/
protected $paths = array(APP_MODELS);
/**
* @var bool $isDevMode - Are we considered "in development."
*/
protected $isDevMode = false;
/**
* @var array $dbParams - The database paramters.
*/
protected $dbParams = null;
/**
* Constructor to set some core values.
*/
public function __construct(){
if (!file_exists('db_config.ini')) {
throw new \Exception(
'Missing db_config.ini. You can create this from the db_config_sample.ini'
);
}
$this->dbParams = array(
'driver' => 'pdo_mysql',
'user' => parse_ini_file('db_config.ini')['DB_USER'],
'password' => parse_ini_file('db_config.ini')['DB_PASSWORD'],
'dbname' => parse_ini_file('db_config.ini')['DB_NAME']
);
}
/**
* Get the entity manager for use through out the app.
*
* @return EntityManager
*/
public function getEntityManager() {
$config = Setup::createAnnotationMetadataConfiguration($this->paths, $this->isDevMode, null, null, false);
return EntityManager::create($this->dbParams, $config);
}
}
/**
* Function that can be called through out the app.
*
* @return EntityManager
*/
function getEntityManager() {
$ds = new DoctrineSetup();
return $ds->getEntityManager();
}
/**
* Function that returns the conection to the database.
*/
function getConnection() {
$ds = new DoctrineSetup();
return $ds->getEntityManager()->getConnection();
}
use \ImageUploader\AppKernel;
$kernel = new AppKernel();
$kernel->loadClassCache();
Я не уверен, почему я получаю эта ошибка, у меня есть модель (сущность), которая выглядит как таковая:
namespace ImageUploader\Models;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="users")
* @UniqueEntity(fields="userName")
* @UniqueEntity(fields="email")
*/
class User {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string", length=32, nullable=false)
* @Assert\NotBlank()
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=32, nullable=false)
* @Assert\NotBlank()
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
* @Assert\NotBlank(
* message = "Username cannot be blank"
*)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
* @Assert\NotBlank()
* @Assert\Email(
* message = "The email you entered is invalid.",
* checkMX = true
*)
*/
protected $email;
/**
* @ORM\Column(type="string", length=500, nullable=false)
* @Assert\NotBlank(
* message = "The password field cannot be empty."
*)
*/
protected $password;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updated_at;
}
Когда я иду, чтобы проверить модель, я получаю указанную выше ошибку. Я установил комплект учения, и я думал, что правильно настроил ситуацию. Но, видимо, нет. Знаете ли вы, что я делаю неправильно?Я установил что-то неправильно или вообще не настроил?
Аналогичная проблема: http://stackoverflow.com/questions/28649091/use-symfony-uniqueentity-with-doctrine – stefita
Возможный дубликат [Class 'doctrine.orm.validator.unique' not found] (http: // stackoverflow.com/questions/30006250/class-doctrine-orm-validator-unique-not-found) –
Вы открыли тот же пост за 8 часов до открытия этого сообщения. Пожалуйста, не публикуйте повторяющиеся вопросы, просто обновите свой исходный вопрос. Если вы хотите получить больше информации о своем вопросе, используйте [bounty] (http://stackoverflow.com/help/bounty). –