小编dea*_*ase的帖子

从doctrine 2中的datetime对象获取日期作为字符串

在我的一个实体中,我有一个被称为受保护的属性insert_date,它是一个日期时间.

当我之后提取数据时,我没有将日期作为字符串,我得到一个对象.我的var转储:

<pre class='xdebug-var-dump' dir='ltr'> <b>object</b>(<i>DateTime</i>)[<i>1560</i>] <i>public</i> 'date' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2011-08-26 12:40:29'</font> <i>(length=19)</i> <i>public</i> 'timezone_type' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>3</font> <i>public</i> 'timezone' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Europe/London'</font> <i>(length=13)</i> </pre><pre class='xdebug-var-dump' dir='ltr'> <b>object</b>(<i>DateTime</i>)[<i>1571</i>] <i>public</i> 'date' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2011-08-26 12:40:29'</font> <i>(length=19)</i> <i>public</i> 'timezone_type' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>3</font> <i>public</i> 'timezone' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Europe/London'</font> <i>(length=13)</i>
Run Code Online (Sandbox Code Playgroud)

我试过了:

foreach($dateObj as $date) {

}
Run Code Online (Sandbox Code Playgroud)

但是它没有提取......我如何从这个对象中获取日期属性?即使$insert_date->date不起作用.

php datetime doctrine doctrine-orm

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

学说2,如何删除多对多关联?

如何在不删除任何内容的情况下将关系从多对多表中取消链接?

我试过了:

$getProject = $this->_helper->getDocRepo('Entities\Project')->findOneBy(array('id' => $projectId));
$getCat = $this->_doctrine->getReference('\Entities\Projectcat', $catId);

$getProject->getCategory()->removeElement($getCat);
$this->em->flush();
Run Code Online (Sandbox Code Playgroud)

我的Projectcat实体:

/**
 * @ManyToMany(targetEntity="\Entities\Projectcat", cascade={"persist", "remove"})
 * @JoinColumn(name="id", referencedColumnName="id")
 */
protected $getCategory;
Run Code Online (Sandbox Code Playgroud)

doctrine doctrine-orm

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

我可以迭代Doctrine2中的Entity属性吗?

我用

$myblogrepo = $this->_doctrine->getRepository('Entities\Blog')->findBy(array('id' => 12);
Run Code Online (Sandbox Code Playgroud)

我通过访问

foreach($myblogrepo as $key =>$value){

echo $key . $value;

}
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得字段名称?我认为key =>会起作用,但它将键打印为0

所以我认为这会奏效:

foreach($myblogrepo[0] as $key =>$value){

echo $key . $value;
}
Run Code Online (Sandbox Code Playgroud)

但仍然没有..}

php doctrine doctrine-orm

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

学说2,查询实体内部

如何在实体中执行查询?

namespace Entities\Members;

/**
 * @Entity(repositoryClass="\Entities\Member\MembersRepository")
 * @Table(name="Members")
 * @HasLifecycleCallbacks
 */
class Members extends \Entities\AbstractEntity
{
    /**
     * @Id @Column(name="id", type="bigint",length=15)
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /** 
     * @Column(name="userid", type="bigint", length=26, nullable=true) 
     */
    protected $userid;

    /** 
     * @Column(name="fname", type="string", length=255,nullable=true) 
     */
    protected $fname;

    /**
     *  @OneToMany(targetEntity="\Entities\Users\Wall", mappedBy="entry", cascade={"persist"}) 
     */
    protected $commententries;

    public function __construct()
    {
        $this->commententries = new \Doctrine\Common\Collections\ArrayCollection();
    }
}
Run Code Online (Sandbox Code Playgroud)

示例我想在这个实体中有一个函数叫做:filter() 我希望能够过滤commententries集合.它应该返回具有某种条件的集合id=1.基本上它应该过滤从连接查询接收的数据.

所以像这样:

$this->commententries->findBy(array('id' => 1));
Run Code Online (Sandbox Code Playgroud)

但显然这不起作用.

php doctrine filter doctrine-orm

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

doctrine 2 - 查询构建器条件查询...如果语句?

我的查询是doctirne 2.我在用户,私人或公共领域都有一个状态字段.我希望能够运行此查询并显示所有注释status = public和private如果userid =当前登录用户ID(我知道,$ 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, $loggerUserVarID)
            ->getQuery();
Run Code Online (Sandbox Code Playgroud)

此刻,我在获得结果后使用if语句,是否有办法在此查询中执行if语句?

doctrine query-builder doctrine-orm

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

如何使用学说 2 在循环中插入多行

我想使用学说 2 在循环中插入多行..

我通常使用这个插入 1 条记录:

$Entity->setData($posted); $this->_doctrine->persist($Entity); $this->_doctrine->flush();

doctrine zend-framework

5
推荐指数
1
解决办法
4534
查看次数

doctrine2 - querybuilder,空参数

如果参数没有值,我该怎么办?

我的查询:

$query = $this->_em->createQueryBuilder()
                   ->select('u')
                   ->from('Users', 'u')
                   ->where('u.id = ?1')                   
                   ->andWhere('u.status= ?2')
                   ->setParameter(1, $userid)
                   ->setParameter(2, $status)
                   ->getQuery();

return $query->getResult();
Run Code Online (Sandbox Code Playgroud)

如果没有$状态,那么它不会显示任何内容.

我尝试在查询之前设置一个条件来检查它是否为null,但是如果没有设置状态,我可以设置$ status的值

doctrine query-builder doctrine-orm

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

使用助手的zend模型

调用未定义的方法Application_Model_Users :: _ helper()

如何让重定向助手在模型中工作?在控制器中工作,扩展zend控制器操作但不在模型中

谢谢

php zend-framework

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

如何在学说中加2小时?

使用以下代码,

protected $token;
 /** @Column(name="assigneddate", type="datetime", columnDefinition="datetime") */
private $assigneddate;


/** @Column(name="expirydate", type="datetime", columnDefinition="datetime") */
private $expirydate;

/** @PreUpdate */
public function updated()
{
    //$this->assigneddate = new \DateTime("now");
}
public function __construct()
{

    $this->expirydate = $this->expirydate = new \DateTime("now");
    $this->assigneddate = $this->assigneddate = new \DateTime("now");
Run Code Online (Sandbox Code Playgroud)

}

我如何添加2小时?

php doctrine-orm

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

学说2.1 - 从收集中删除

我试图从父实体中删除注释,我记得在我的上一个网站上这样做,但现在它不起作用..

我的实体 - 用户

namespace Application\Entities;

use Doctrine\ORM\Mapping AS ORM,
    Doctrine\Common\Collections\ArrayCollection;

/**
 * Loan
 *
 * @ORM\Table(name="users")
 * @ORM\Entity
 */
class Users{

    /**
     * @var integer $id
     *
     * @ORM\Column(type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;


    /**
     * @var string $username
     *
     * @ORM\Column(type="string", length=45, nullable=false)
     */
    private $username;

    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="Comments", mappedBy="author", cascade={"persist", "remove"})
     */
    private $comments;

    public function getComments(){

          return $this->comments;              

    }
Run Code Online (Sandbox Code Playgroud)

和我的评论表:

    namespace Application\Entities;

    use Doctrine\ORM\Mapping AS ORM,
        Doctrine\Common\Collections\ArrayCollection;

/**
 * …
Run Code Online (Sandbox Code Playgroud)

php doctrine doctrine-orm

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