doctrine

zend-framework doctrine, and mvc pattern: what kind of layer should connect data between models and forms?

房东的猫 提交于 2020-01-01 10:48:08
问题 I am learning Zend Framework and Doctrine. I am wondering what is the best practice to connect forms to models and vice versa. In some cases it is handy to load data from model in form class. Lets say a very unique class which use many models. In other cases it is convenient to have methods in model class which prepares data for forms. Lets say it could have a method which returns an array prepared for select-options element, so this method will be useful for many forms. I would like to have

Doctrine fetch join

一个人想着一个人 提交于 2020-01-01 10:14:09
问题 First I will give an example with some pseudo code and then I will explain what is the problem. Let me say I have two entities User and Phonenumber. Their relation is one-to-many. In my UserRepository I can have something like that: class UserRepository { public function getUser($id, $type) { $users = $this->createQuery("SELECT u, p FROM User u JOIN u.phonenumbers p WHERE u.id = :id AND p.type = :type") ->setParameters(array( 'id' => $id, 'type' => $type, )) ->getResult(); return $users[0]; }

doctrine 2 - query builder conditional queries… If statements?

半世苍凉 提交于 2020-01-01 09:43:18
问题 My query is doctirne 2. i have a status field in users, private or public. i want to be able to run this query and display all comments where status= public and private only if userid = current logged in user id(which i know, $loggerUserVarID) $q = $this->em->createQueryBuilder() ->select('c') ->from('\Entities\Comments', 'c') ->leftJoin('c.users', 'u') ->where('status = public') ??? display all public comments but private if it belpongs to the logged in user.? ->setParameter(1,

Doctrine undefined function apc_fetch

左心房为你撑大大i 提交于 2020-01-01 08:17:28
问题 I'm using this tutorial, which gives a detail explanation about how to set up CodeIgniter and Doctrine. I'm using CodeIgniter 2.1.0 and Doctrine 2.2.1, but I get this error: Fatal error: Call to undefined function Doctrine\Common\Cache\apc_fetch() in /Applications/XAMPP/xamppfiles/htdocs/emma_watson_shrine/application/libraries/Doctrine/Common/Cache/ApcCache.php on line 52 Can you help me out? 回答1: You need to enable the APC extension for PHP. Follow this guide. Alternatively, you could use a

Doctrine Query Builder using Array

我只是一个虾纸丫 提交于 2020-01-01 06:28:06
问题 I have an array of id: Id_array; //array(2) { [0]=> int(9) [1]=> int(10) } I simply want to select the users using Id_array; I managed to do this when I don't have an array but just an integer: $query = $em->createQuery('SELECT u FROM Users u WHERE u.id = ?1'); $query->setParameter(1, 9); // I tested the value 9 here $users = $query->getResult(); How can I fetch all the users that correspond to Id_array? 回答1: Or without the query builder: $query = $em->createQuery('SELECT u FROM Users u WHERE

PDO connection error when using symfony and MAMP

白昼怎懂夜的黑 提交于 2020-01-01 04:29:12
问题 Getting an PDO error when trying to do php symfony doctrine:insert-sql The error I get: Warning: PDO::__construct(): [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/johannes/Programmering/PHP/htdocs/symfony/sfprojects/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470 databases.yml all: doctrine: class: sfDoctrineDatabase param: dsn: mysql:host=127.0.0.1;dbname=jobeet; username: root password: root Doing a

How to access old values on PrePersist LifecycleCallback in Doctrine2

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 04:23:06
问题 I have an entity in Doctrine2 and use the HasLivecycleCallbacks with PrePersist. In general this works fine, but I would like to change the version only, when certain fields in my entity change. Do I have a chance to get the old Values? Or just the keys that have been changed? /** * @ORM\HasLifecycleCallbacks */ class Person { /** * @PrePersist * @PreUpdate */ public function increaseVersion() { if ( $this->version == null ) { $this->version = 0; } // only do this, when a certain attribute

Injecting the Service Manager to Build a Doctrine Repository in ZF2

∥☆過路亽.° 提交于 2020-01-01 03:49:10
问题 How do I inject the service manager into a Doctrine repository to allow me to retrieve the Doctrine Entity Manager? I using the ZF2-Commons DoctrineORMModule and are trying to implement the repository example listed in the Doctrine Tutorial (bottom of tutorial in link below): http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html However, I keep getting a message " Fatal error: Call to a member function get() on a non-object in C:\zendProject\zf2 ... "

Symfony2 getdoctrine outside of Model/Controller

柔情痞子 提交于 2020-01-01 03:29:07
问题 I'm trying to getDoctrine() outside of the controller. I've created this service: config/services.yml services: update_command: class: project\projBundle\Command\Update arguments: ['@doctrine.orm.entity_manager'] and in my app/config/config.yml imports: - { resource: "@projectprojBundle/Resources/config/services.yml" } so and the class that I want to use: namespace project\projBundle\Command; use Doctrine\ORM\EntityManager; class Update { protected $em; public function __construct

Doctrine - how to get the SQL INSERT query, in the postSave() event?

岁酱吖の 提交于 2020-01-01 03:21:10
问题 I would like to get the exact SQL INSERT query that Doctrine generates when an object's save() method is called. Preferably, I would like to get it in the postSave() event of the model and log it in a txt file. For instance: <?php $user = new User(); // A Doctrine Model with timestampable behavior enabled $user->first_name = 'Manny'; $user->last_name = 'Calavera'; $user->save(); ?> I want to get/log the following SQL query: INSERT INTO user (first_name, last_name, created_at, updated_at)