doctrine

Symfony - Form item as plain text

别来无恙 提交于 2019-12-24 07:06:09
问题 I have a form that contains a collection of forms (a Vote with many VoteChoice ). The VoteChoiceType is as follows class VoteChoiceType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('answer', null, array('disabled' => true)) ->add('priority', null); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'PollBundle\Entity\VoteChoice', )); } } Now in my Controller I create

Doctrine - query with date range

徘徊边缘 提交于 2019-12-24 06:52:04
问题 I wrote a query that I can call within my form to select date range and to return all database data in that range. The api call works fine but when I set date parameters it returns an empty result. $date = new \Datetime(); $result = $this->getMyRepository() ->createQueryBuilder('a') ->select('a') ->where('a.date >= :from') ->andWhere('a.date <= :to') ->setParameter('from', $date->format('Y-m-d H:i:s')) ->setParameter('to', $date->format('Y-m-d H:i:s')) ->orderBy('a.id') ->getQuery() -

doctrine persist php class which inherit doctrine entity

余生长醉 提交于 2019-12-24 06:45:07
问题 Is it possible to have a php class which extends a doctrine entity and to persist it ? example: /** * @Entity */ class A { /** * @ORM\ManyToMany(targetEntity="C", mappedBy="parents") */ protected $children; } class B extends A { ... } class C { /** * @ORM\ManyToMany(targetEntity="A", inversedBy="children") */ protected $parents; } $b = new B(); $em->persist($b); 回答1: Yes it's possible, this is called inheritance mapping, but the child class has to be explicitly declared as @Entity and its

Correct way to do a migrations diff

拥有回忆 提交于 2019-12-24 06:22:59
问题 I'm trying to perform a migrations diff between the schema yaml file and my database, using the following code $migration = new Doctrine_Migration($migrationsPath); $diff = new Doctrine_Migration_Diff(null, $yamlSchemaPath, $migration); $changes = $diff->generateMigrationClasses(); $numChanges = count($changes, true) - count($changes); From what I gather, $from = null here would imply that the from in comparison will be read from the database, but that does not seem to be the case. Reading

Select specific columns from a repository in Doctrine 2

浪子不回头ぞ 提交于 2019-12-24 04:44:09
问题 First, we know that depending on the amount of columns in a query, may increase the response time. In Doctrine call the following store, which has a relationship and it brings all the columns of both entities. public function index() { $this->students = $this->model->getRepository()->findAll(); } But thinking about the statement that I gave earlier, the return of this repository is more time consuming than if it was a non-relationship? And other questions. Can I select the columns that I want

Doctrine “has no association named”

為{幸葍}努か 提交于 2019-12-24 04:37:09
问题 Add me to the list of people who can't work out what's wrong with their Doctrine mapping. I'm modelling a Chess Game with OneToMany Halfmoves - any ideas? DDL: create table game ( game_id int primary key ); create table halfmove(halfmove_id int primary key, game_id int); Game.php: /** * Game * * @ORM\Table(name="game") * @ORM\Entity */ class Game { /** * @ORM\OneToMany(targetEntity="Halfmove", mappedBy="game") */ private $halfmoves; public function getHalfmoves(){ return $this->halfmoves; }

Doctrine2 Two repositories on the same entity

别等时光非礼了梦想. 提交于 2019-12-24 04:18:08
问题 I don't know how to clearly explain my problem but i'll try :) I have a project with two modules: Admin User I also have two doctrine entities that cause me some troubles: Shop Products My problem is that theses entities must be used by the Admin and User module, but with doctrine one Entity = one Repository (as far as i know). How can i for having an working folders structure with doctrine like that: -db -entities -Shop.php -Product.php -repositories -admin_ShopRepository.php (work with Shop

The file could not be found while using LifecycleCallbacks

懵懂的女人 提交于 2019-12-24 03:44:12
问题 I have problem with form validation in symfony2 . In my case the $form->isValid() command results in The file could not be found. even though that I provide a file during filling in the form Additionally debuging of setFile function in documents entity leads to conclusion that file value is set correctly. The setFile function and results of print_r are provided below: /** * Sets file. * * @param UploadedFile $file */ public function setFile(UploadedFile $file = null) { $this->file = $file;

Symfony 2 doctrine persist doesn't work after updating Relationship Mapping

时间秒杀一切 提交于 2019-12-24 03:37:49
问题 I updated my entity file to include relationship mapping. Persist worked before the update now it doesn't. Maybe it's something I forgot to do. namespace classes\classBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * advisersplans * * @ORM\Table() * @ORM\Entity */ class advisersPlans { /** * * @ORM\ManyToOne(targetEntity="plans", inversedBy="adviserPlans") * @ORM\JoinColumn(name="planid", referencedColumnName="id") */ public $plan; /** * @var integer * * @ORM\Column(name="id", type=

Symfony2 : Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given

ぐ巨炮叔叔 提交于 2019-12-24 03:34:33
问题 I'm trying to implement OAuth2 in my actual symfony2 project using the FOSOAuthServerBundle. I've been following this Article to implement it. Since i don't use FOS User bundle i had to create a UserProvider. I'm also using A User Repository as he did in his Article. I've been stuck with this error : ContextErrorException: Catchable Fatal Error: Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given, called in