How to get a Zend model using a field

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 PDO is displayed as follows:

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 opinion, I want to get articlesthat have a field rubrique == "club":

To get all the elements, this code works fine with fetchAll():

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

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

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

+3
source share
1 answer

You can use fetchAll()to complete the task, without having to write a method to do this:

In controller action:

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

Source: https://habr.com/ru/post/1752851/


All Articles