How to select randomly with doctrine

The Doctrine team is not willing to implement this feature. There are several solutions to your problem, each having its own drawbacks: Add a custom numeric function: see this DQL RAND() function (might be slow if you have lots of matching rows) Use a native query (I personally try to avoid this solution, which I … Read more

How to encode Doctrine entities to JSON in Symfony 2.0 AJAX application?

With php5.4 now you can do : use JsonSerializable; /** * @Entity(repositoryClass=”App\Entity\User”) * @Table(name=”user”) */ class MyUserEntity implements JsonSerializable { /** @Column(length=50) */ private $name; /** @Column(length=50) */ private $login; public function jsonSerialize() { return array( ‘name’ => $this->name, ‘login’=> $this->login, ); } } And then call json_encode(MyUserEntity);