phpdoctrine

How to perform a simple SELECT with doctrine?


Select * from tableName order by id desc limit 10

How to perform something like the above with doctrine by a demo?


Solution

  • Inside the model's Table class (eg tableNameTable.class.php):

    function getResults()
    {
      $results = self::createQuery("q")
        ->select("q.*")
        ->orderBy("q.id DESC")
        ->limit(10)
        ->execute();
    
      return $results;
    }
    

    will give you a Doctrine Collection of results.