Sonata Media Bundle sortBy created_at

Posted by tony908 on Stack Overflow See other posts from Stack Overflow or by tony908
Published on 2014-06-09T21:21:34Z Indexed on 2014/06/09 21:24 UTC
Read the original article Hit count: 216

Filed under:
|
|

I use SonataMediaBundle and i would like sort Gallery by created_at field. In repository class i have (without orderBy working good!):

    $qb = $this->createQueryBuilder('m')
        ->orderBy('j.expires_at', 'DESC');

    $query = $qb->getQuery();

    return $query->getResult();

and this throw error:

An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 80 near 'created_at D': Error: Class Application\Sonata\MediaBundle\Entity\Gallery has no field or association named created_at")

so i add this field to Gallery class:

/**
 * @var \DateTime
 */
private $created_at;




/**
 * Set created_at
 *
 * @param \DateTime $createdAt
 * @return Slider
 */
public function setCreatedAt($createdAt)
{
    $this->created_at = $createdAt;

    return $this;
}

/**
 * Get created_at
 *
 * @return \DateTime 
 */
public function getCreatedAt()
{
    return $this->created_at;
}

but now i have error:

FatalErrorException: Compile Error: Declaration of Application\Sonata\MediaBundle\Entity\Gallery::setCreatedAt() must be compatible with Sonata\MediaBundle\Model\GalleryInterface::setCreatedAt(DateTime $createdAt = NULL) in /home/tony/www/test/Application/Sonata/MediaBundle/Entity/Gallery.php line 32

GalleryInterface:

https://github.com/sonata-project/SonataMediaBundle/blob/master/Model/GalleryInterface.php

So... how can i use sortBy in my example?

© Stack Overflow or respective owner

Related posts about php

Related posts about symfony2