doctrine

How to force Doctrine to update array type fields?

╄→尐↘猪︶ㄣ 提交于 2020-01-19 05:32:05
问题 I have a Doctrine entity with array type field: /** * @ORM\Table() */ class MyEntity { (...) /** * @var array $items * * @ORM\Column( type="array" ) */ private $items; /** * @param SomeItem $item */ public function addItem(SomeItem $item) { $this->items[] = $item; } (...) } If I add element to the array, this code works properly: $myEntityObject->addItems(new SomeItem()); $EntityManager->persist($myEntityObject); $EntityManager->flush(); $myEntityObject is saved to the database with correct

creating mapped ORM Entities without the cli?

可紊 提交于 2020-01-17 03:59:09
问题 I'm working on an apiglity project that uses zend framework 2 and the doctrine. i included in local.config.php of my zf2 project the following code: return array( 'doctrine' => array( 'connection' => array( 'orm_default' => array( 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'user' => '<username>', 'password' => '<password>', 'dbname' => '<db>', ) ) ) ), ); in my main module's configuration file (module.config.php) I

What is correctness in symfony to fill a form in two steps?

青春壹個敷衍的年華 提交于 2020-01-17 03:26:08
问题 Hy, What is correctness in symfony to fill a form in two steps? Imagine that we have a entity called Enterprise and we want to create a form with only required fields and another form, that when the user login can fill the other non-required fields. How is the correctness form? Now i have a form to registration ('lib/form/doctrine/EnterpriseForm.class.php') and another ('lib/form/doctrine/EnterpriseCompleteForm.class.php').In every class we set labels, validators, ... but the problem is in

Get symfony doctrine findAll to return array with specific type of keys

爱⌒轻易说出口 提交于 2020-01-17 01:45:07
问题 I'm looking for elegant way to restructure the array returned by Symfony findAll with specific keys. For instance If I have an entity Animal with fields id, name, color etc. I would like to make a repository method that returns an array with all animals and the key for each one to be the 'name' field so I can make lookups in this array. The way I'm doing it now is by iterating the array and creating a new one, but I'm wondering if there is something ready made that I can use? 回答1: No there is

Doctrine many to many: has user liked the article?

心已入冬 提交于 2020-01-16 19:48:35
问题 I have 2 Entities User Article and a “likedByUsers” Many To Many relationship between both. When I show an article, I want to know if the user has liked it so a heart icon is shown. I've got this in the ArticleRepository: public function findOneBySlug($slug,$userId): ?Pack { return $this->createQueryBuilder('p') ->andWhere('p.slug = :val') ->setParameter('val', $slug) ->addSelect('COUNT(u) AS userLike', 'p') ->leftJoin("p.users", 'u', 'WITH', 'u.id = :userId') ->setParameter('userId', $userId

Doctrine many to many: has user liked the article?

荒凉一梦 提交于 2020-01-16 19:48:22
问题 I have 2 Entities User Article and a “likedByUsers” Many To Many relationship between both. When I show an article, I want to know if the user has liked it so a heart icon is shown. I've got this in the ArticleRepository: public function findOneBySlug($slug,$userId): ?Pack { return $this->createQueryBuilder('p') ->andWhere('p.slug = :val') ->setParameter('val', $slug) ->addSelect('COUNT(u) AS userLike', 'p') ->leftJoin("p.users", 'u', 'WITH', 'u.id = :userId') ->setParameter('userId', $userId

Generate entity in symfony 4 (methods)

偶尔善良 提交于 2020-01-16 18:46:35
问题 when I tried to run the command php bin/console doctrine:generate:entities App:Center in symfony 4.0.6 I get this error: Can't find base path for "App\Entity\Center" (path: "/home/USER/foo/bar/src/Entity", destination: "/home/USER/foo/bar/src/Entity"). the Center is my entity name! how can I fix this? 回答1: Doctrine developers are deprecating the generation commands for Symfony 4. The reason why it doesn't work for you is because the command is hardwired to find the destination directory under

Generate entity in symfony 4 (methods)

柔情痞子 提交于 2020-01-16 18:46:07
问题 when I tried to run the command php bin/console doctrine:generate:entities App:Center in symfony 4.0.6 I get this error: Can't find base path for "App\Entity\Center" (path: "/home/USER/foo/bar/src/Entity", destination: "/home/USER/foo/bar/src/Entity"). the Center is my entity name! how can I fix this? 回答1: Doctrine developers are deprecating the generation commands for Symfony 4. The reason why it doesn't work for you is because the command is hardwired to find the destination directory under

Edit file name in entity with Symfony

[亡魂溺海] 提交于 2020-01-16 12:06:11
问题 Hello (excuse my English, not too confident with it) I'm actually working on a Symfony website that display some spectacles' information. For now, I need to add an image when I create one of them. I managed to do so with the help of this tutorial. It basically works like this: I upload an image into site's directory and then send file's name to the entity (Store in a MySQL database) . I can then display the image in spectacle's details. The issue appeared when I want to edit a spectacle. I

doctrine 2, how do get data from the inverse side (many to one)

左心房为你撑大大i 提交于 2020-01-16 09:04:32
问题 I have two entities, entry and comments. comments: /** * @Entity(repositoryClass="\Entities\Blog\CommentRepository") * @Table(name="blog_comment") * @HasLifecycleCallbacks */ class Comment extends \Entities\AbstractEntity { /** * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; /** * @ManyToOne(targetEntity="Entry", inversedBy="comments") * @JoinColumn(name="entry_id", referencedColumnName="id") */ protected $entry; /** @Column(name="approved", type=