小编dev*_*eep的帖子

使用具有多对多关系的EntityRepository :: findBy()将导致Doctrine中的E_NOTICE

对于Symfony2项目,我必须在博客文章和所谓的平台之间建立关系.平台根据您用于查看站点的域定义特定过滤器.例如:如果您通过url first-example.com加入该网站,该网站将仅提供与此特定平台相关联的博客帖子.

为此,我创建了两个实体Post和Platform.之后我将它们与多对多关系映射在一起.我正试图通过findBy()Doctrines中内置函数的多对多关系来检索数据EntityRepository.

// every one of these methods will throw the same error
$posts = $postRepo->findBy(array('platforms' => array($platform)));
$posts = $postRepo->findByPlatforms($platform);
$posts = $postRepo->findByPlatforms(array($platform));
Run Code Online (Sandbox Code Playgroud)

实体和现有对象$postRepo的正确存储库在哪里. 无论哪种方式:我最终得到以下错误:Post$platformPlatform

ErrorException: Notice: Undefined index: joinColumns in [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1495

[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1495
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1452
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1525
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:1018
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php:842
[...]/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:157
[...]/src/Foobar/BlogBundle/Tests/ORM/PostTest.php:102
Run Code Online (Sandbox Code Playgroud)

是否有可能以这种方式以多对多关系检索相关的entites,或者我被迫自己编写这些函数?奇怪的是:Doctrine不会抛出任何错误:"这不可能.",但是内部E_NOTICE.这就是为什么我认为它应该是可能的,但我在这里错过了一些观点.

剥离到有趣的部分,这两个实体看起来像这样.

<?php

namespace Foobar\CommunityBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

// [...] other namespace stuff

/**
 * @ORM\Entity(repositoryClass="Foobar\CommunityBundle\Entity\Repository\PlatformRepository")
 * @ORM\Table(name="platforms")
 */
class Platform
{
    /** …
Run Code Online (Sandbox Code Playgroud)

php doctrine many-to-many database-relations symfony

32
推荐指数
2
解决办法
4万
查看次数

使用OneupUploaderBundle上传的实体文件的简单示例

我尝试使用OneupUploaderBundle上传文件.我多次阅读此捆绑包的文档,但我没有设法找到要上传文件的实体的任何简单示例.我的期望是一个类似于以下的类定义VichUploaderBundle:

<?php

namespace Minn\AdsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Entity
 * @Vich\Uploadable
 */
class MotorsAdsFile {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    public $id;

    /**
     * @Assert\File(
     *     maxSize="5M",
     *     mimeTypes={"image/png", "image/jpeg"}
     * )
     * @Vich\UploadableField(mapping="motors_files", fileNameProperty="filename")
     * note: This is not a mapped field of entity metadata, just a simple property.
     * @var File $file
     */
    protected $file;

    /**
     * @ORM\Column(type="string", length=255, …
Run Code Online (Sandbox Code Playgroud)

file-upload symfony jquery-file-upload oneupuploaderbundle

6
推荐指数
1
解决办法
7883
查看次数