views:

24

answers:

1

I have a database table that looks like this:

  CREATE TABLE IF NOT EXISTS `articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `texte` varchar(255) NOT NULL,  
  `rubrique` varchar(255) NOT NULL,
  PRIMARY KEY (id)
);

Which is PDO mapped like this:

class Application_Model_DbTable_Articles extends Zend_Db_Table_Abstract
{
    protected $_name = 'articles';

   //this is where I have a problem 
   public function getArticleByRubrique($rubrique) 
    {        
        $row = $this->fetchRow('rubrique = ' . $rubrique);    
        return $row->toArray();    
    }  

}

In my view I want to fetch the articles that have field rubrique == "club" :

To fetch all the items, this code works fine using fetchAll():

$articles = new Application_Model_DbTable_Articles();
        $this->view->articles = $articles->fetchAll();

But when I do it with getArticleByRubrique() I get this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'club' in 'where clause'

+2  A: 

You can still use fetchAll() to do the job, without needing to write a method just to do that:

In the controller's action:

$articles = new Application_Model_DbTable_Articles();
$this->view->articles = $articles->fetchAll('rubrique = "club"');
Bakkal