标签: doctrine-orm

doctrine2可以从阵列中为一个新实体加水吗?

我认为标题要求一切.很简单,我有一个实体:

class User {
    private $id;
    private $name;
    private $username;
}
Run Code Online (Sandbox Code Playgroud)

与所有适当的setter和getter.我有一个数组:

array( 'name' => 'joe', 'username' => 'shmoe' );
Run Code Online (Sandbox Code Playgroud)

我希望能够做到这样的事情:

Some\Unknown\Doctrine\Object::hydrateFromArray($array);
Run Code Online (Sandbox Code Playgroud)

显然创建一个函数来为它提供一个对象是很容易的,但是肯定教义必须有一些内容来实现这个目标吗?

php doctrine-orm

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

如何确定Doctrine 2中的表关系是双向还是单向?

我正在Zend应用程序中从Doctrine 1.1.4升级到Doctrine 2.0.6.

目前,我正在研究实体之间的关联.在Doctrine 2的文档中,它说'关系可能是双向的或单向的.我很困惑这些术语在给定的上下文中意味着什么.

如何确定关系是单向还是双向?

感谢帮助.

php mapping zend-framework models doctrine-orm

20
推荐指数
1
解决办法
4080
查看次数

Symfony2/Doctrine,必须将业务逻辑放在我的控制器中?和复制控制器?

我的应用程序中有一个复杂的定价机制 - 以下是我设置阶段的一些业务规则(实体是粗体):

  • 一个产品可能具有独特的价位对于给定的客户,网站客户群.
  • 一个产品有时可以有一个或多个附加选项,可能有自己的价格点 价格规则.
  • 产品具有一个独特的添加由用户,这本质上是一种价格和一个整数选择.

现在,我有一个价格点的EntityRepository,基本上确定了基本产品的正确价格点.这同样适用于在独特的加法选项.

PricePointRepository

public function getThePrice($Product, $qty, $Website, $Customer = null) 
{
    //all logic to get product price for this given instance goes here. Good.
}
Run Code Online (Sandbox Code Playgroud)

控制器(简化)

public function indexAction() 
{
    $Product = $em->dostuffwithpostdata;
    $qty = POST['qty']; //inb4insecure trolls
    $Website = $em->dostuff();
    $Customer = (if …
Run Code Online (Sandbox Code Playgroud)

model-view-controller orm business-logic symfony doctrine-orm

20
推荐指数
2
解决办法
5462
查看次数

获取doctrine2实体中的列名称

如何获取教义实体中所有列的名称?

doctrine-orm

20
推荐指数
1
解决办法
2万
查看次数

使用Symfony + Doctrine的环境特定数据夹具

使用Smyfony2和Doctrin2,可以使用以下示例创建数据夹具:http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html

我想要的是能够使用这个概念进行测试,以便setup/teardown可以为功能测试创建一个纯粹的测试数据环境.我如何在功能测试期间运行一组特定的仅测试夹具,如何将这些夹具与我的标准夹具分开,以便控制台命令忽略它们?

似乎这样做的方法是复制doctrine:fixtures控制台命令的功能并将测试装置存储在其他地方.有没有人有更好的解决方案?

symfony doctrine-orm

20
推荐指数
2
解决办法
7527
查看次数

Doctrine2 Paginator获得总结果

我会立刻说,我读了这个问题Doctrine2 Paginator,但它并没有给我足够的信息来提供我的问题的标题.

当我使用Doctrine1时,我得到了这样的代码的结果,例如:

$list = $this->query
    ->addSelect( 'SQL_CALC_FOUND_ROWS *' )
    ->offset( ( $this->currentPage - 1 ) * $this->perPage )
    ->limit( $this->perPage )
    ->execute( array(), \Doctrine_Core::HYDRATE_ARRAY_SHALLOW );

$totalRecords     = SqlCalcFoundRowsEventListener::getFoundRowsCount();
$this->totalPages = ceil( $totalRecords / $this->perPage );
Run Code Online (Sandbox Code Playgroud)

这很棒.

现在,当使用Doctrine2时,我很困惑我应该如何获得与当前页面的有限结果相同的查询的总记录数量.

任何帮助/建议将不胜感激.

php pagination doctrine-orm

20
推荐指数
1
解决办法
2万
查看次数

Doctrine 2 - 如何添加自定义DBAL驱动程序?

如何在不修改Doctrine2核心中的DriverManager.php的情况下添加自定义驱动程序?

我已经创建了一个DBAL驱动程序pdo_dblib并将其放在Symfony2包中.这工作正常,但我必须将我的驱动程序添加到DriverManager.php中的硬编码驱动程序列表,否则我得到以下异常:

例外

[Doctrine\DBAL\DBALException]                                                                                                                                                   
The given 'driver' pdo_dblib is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_ibm, pdo_sqlsrv
Run Code Online (Sandbox Code Playgroud)

除非我修改DriverManager.php

final class DriverManager
{
    private static $_driverMap = array(
        'pdo_dblib' => 'Doctrine\DBAL\Driver\PDODblib\Driver', // Added this line
    );
}
Run Code Online (Sandbox Code Playgroud)

这是我的config.yml:

# Doctrine Configuration
doctrine:
    dbal:
        driver:         pdo_dblib
        driver_class:   PDODblibBundle\Doctrine\DBAL\Driver\PDODblib\Driver
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

19
推荐指数
1
解决办法
1万
查看次数

错误:预期的Doctrine\ORM\Query\Lexer :: T_WITH,"开启"

我编写了以下代码来从数据库中获取数据

function getnotificationAction()
{
    $session = $this->getRequest()->getSession();
    $userId = $session->get('userid');

    $entitymanager = $this->getDoctrine()->getEntityManager();
    $notification = $entitymanager->getRepository('IGCNotificationBundle:Notifications');
    $userNotification = $entitymanager->getRepository('IGCNotificationBundle:Usernotifications');
    $query = $entitymanager
                 ->createQuery("SELECT n.notificationid, n.title,n.notificationmessage, u.creationdate, u.notificationid, u.messagestatus From IGCNotificationBundle:Notifications AS n JOIN IGCNotificationBundle:Usernotifications AS u ON u.notificationid = n.notificationid WHERE u.userId = :userId ORDER BY n.creationdate DESC")->setParameter('userId', userId);

    $notifications = $query->getResult();

    return $this->render('IGCNotificationBundle:Default:notification.html.twig', array('notifications' => $notifications));
} }
Run Code Online (Sandbox Code Playgroud)

但它是givin

function getnotificationAction()
{
    $session = $this->getRequest()->getSession();
    $userId = $session->get('userid');

    $entitymanager = $this->getDoctrine()->getEntityManager();
    $notification = $entitymanager->getRepository('IGCNotificationBundle:Notifications');
    $userNotification = $entitymanager->getRepository('IGCNotificationBundle:Usernotifications');
    $query = …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

19
推荐指数
1
解决办法
3万
查看次数

Doctrine manyToMany返回PersistentCollection而不是ArrayCollection

我正在使用Symfony 3.1和Doctrine 2.5.

我像往常一样设置了很多ToMany关系:

manyToMany:
        placeServices:
            targetEntity: Acme\MyBundle\Entity\PlaceService
            joinTable:
                name: place_place_service
                joinColumns:
                    place_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    place_service_id:
                        referencedColumnName: id
Run Code Online (Sandbox Code Playgroud)

并向我的实体添加方法

    protected $placeServices;

    ...

    public function __construct()
    {
        $this->placeServices = new ArrayCollection();
    }

    ...

    /**
     * @return ArrayCollection
     */
    public function getPlaceServices(): ArrayCollection
    {
        return $this->placeServices;
    }

    /**
     * @param PlaceServiceInterface $placeService
     * @return PlaceInterface
     */
    public function addPlaceService(PlaceServiceInterface $placeService): PlaceInterface
    {
        if(!$this->placeServices->contains($placeService)) {
            $this->placeServices->add($placeService);
        }

        return $this;
    }

    /**
     * @param PlaceServiceInterface $placeService
     * @return PlaceInterface
     */
    public function removePlaceService(PlaceServiceInterface …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm php-7

19
推荐指数
1
解决办法
1万
查看次数

嵌入表单集合错误:无法确定属性的访问类型

根据本教程,我正在尝试嵌入Tag表单集合.和实体有多对多的关系.ServiceTagService

表单正确呈现.但是当我提交表格时,我得到了

无法确定属性"tagList"的访问类型

错误.我不明白为什么通过调用方法Tag没有将新对象添加到Service类中addTag().

服务类型

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('title', TextType::class, array(
            'label' => 'Title'
        ))
    ;

    $builder->add('tagList', CollectionType::class, array(
        'entry_type' => TagType::class,
        'allow_add' => true,
        'allow_delete' => true,
        'by_reference' => false
    )));
}
Run Code Online (Sandbox Code Playgroud)

服务类

{
....
 /**
 * @ORM\ManyToMany(targetEntity="Tag", mappedBy="serviceList",cascade={"persist"})
 */ 
private $tagList;

/**
 * @return ArrayCollection
 */
public function getTagList()
{
    return $this->tagList;
}

/**
 * @param Tag $tag
 * @return …
Run Code Online (Sandbox Code Playgroud)

symfony-forms symfony doctrine-orm

19
推荐指数
1
解决办法
3460
查看次数