doctrine

Doctrine DQL, class table inheritance and access to subclass fields

独自空忆成欢 提交于 2019-12-18 11:53:17
问题 I have a problem with a DQL query and entity specialization. I have an Entity called Auction , which is OneToOne relation with Item . Item is a mappedSuperclass for Film and Book . I need a query that could back a search engine, allowing the user to look for auctions with different properties AND selling items with different properties (it is the AND part that makes it challenging). The problem is that even though Auction has an association pointing to Item as such, I need to have access to

Doctrine 2: Query result as associative array

久未见 提交于 2019-12-18 11:47:45
问题 In my Repository class I use the following code to query: $query = $this->getEntityManager()->createQuery(" SELECT s.term, COUNT(s.term) AS freq FROM App\Entities\SearchTerm s GROUP BY s.term ORDER BY s.term ASC "); $result = $query->getResult(); The result I get is something like: array (size=4) 0 => array (size=2) 'term' => string '' (length=0) 'freq' => string '1' (length=1) 1 => array (size=2) 'term' => string 'foo' (length=3) 'freq' => string '1' (length=1) 2 => array (size=2) 'term' =>

Symfony 2 Form with select list

旧巷老猫 提交于 2019-12-18 10:57:28
问题 How can i create a select list with values from a database table in Symfony 2? I have 2 entities: Student and Classroom with a ManyToOne relationship and i need to create a form with the folowing fields: name , surname , age , classroom (select list from available classes). In my Student Form i have $builder ->add('name') ->add('surname') ->add('age') ->add('classroom', new ClassroomType()) ; In my Classroom Form i have this: $classrooms =$this->getDoctrine()->getRepository('UdoCatalogBundle

Zend Framework 1.9 and Doctrine Integration

余生颓废 提交于 2019-12-18 10:57:10
问题 I'm trying to setup Zend Framework and Doctrine. There is this previous discussion with ZF 1.8 Integrate Doctrine with Zend Framework 1.8 app That discussion doesn't take into account the AutoLoader / Bootstrap System. If I generate an application skeleton with ./zh.sh how would I go about integrating Doctrine. 回答1: Found a solution http://pastie.org/481635 http://pastie.org/481633 Setup autoloader and plugin path in application/configs/application.ini: autoloadernamespaces.0 = "Doctrine"

FOSUserBundle - PHPUnit - Mock a user

孤街醉人 提交于 2019-12-18 08:55:37
问题 I am using Symfony with the FOSUserBundle and now I like to test some things like: Doctrine lifecycle Controller behind firewall For those tests I need to be a specific user or at least in a user group. How do I mock a user session so that ... The lifecycle field like "createdAt" will use the logged in user The Controller act like some mocked user is logged in Example: class FooTest extends ... { function setUp() { $user = $this->getMock('User', ['getId', 'getName']); $someWhereGlobal->user =

DQL query with joining table and two join

痞子三分冷 提交于 2019-12-18 08:34:50
问题 I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} * ) */ protected $groups; ... } and /** * @ORM\Entity(repositoryClass="Myapp\UserBundle\Repository\GroupRepository") * @ORM\Table(name="groups") */ class

DQL query with joining table and two join

家住魔仙堡 提交于 2019-12-18 08:32:24
问题 I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} * ) */ protected $groups; ... } and /** * @ORM\Entity(repositoryClass="Myapp\UserBundle\Repository\GroupRepository") * @ORM\Table(name="groups") */ class

Chaining orX in Doctrine2 query builder

和自甴很熟 提交于 2019-12-18 03:58:25
问题 I have to dynamically add OR expressions to the query builder returned by getListQueryBuilder , right after adding a where clause. I can't find any suitable way of doing this, i'm just started learning Doctrine. How can i "chain" a given number of orX and add them to my builder? public function getListQueryBuilder($ownerId) { $qb = $this->createQueryBuilder('t'); return $qb ->where($qb->expr()->eq('t.user', ':user')) ->setParameter('user', $ownerId); } $builder = getListQueryBuilder(4); //

Doctrine 2 ManyToMany cascade

一笑奈何 提交于 2019-12-18 03:54:46
问题 Is it possible in Doctrine 2 to create two objects that are many to many related and call persist only on one of them to save both? User entity: /** * Owning Side * * @ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"}) * @JoinTable(name="user_roles", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="role_id", referencedColumnName="id")} * ) */ public $roles; Role entity: /** * Inverse Side * * @ManyToMany

Opcode (APC/XCache), Zend, Doctrine, and Autoloaders

喜欢而已 提交于 2019-12-18 03:39:27
问题 I am trying to use either APC or XCache as an opcode to cache my php pages. I am using it with Zend and Doctrine and it's having a problem with the autoloader. If I try with APC, I get the following: Fatal error: spl_autoload() [<a href='function.spl-autoload'>function.spl-autoload</a>]: Class Doctrine_Event could not be loaded in C:\\[mydir]\\library\\doctrine\\Doctrine\\Record.php on line 777 If I try with XCache I get the following: PHP Fatal error: Cannot redeclare class Zend_Registry in