Note that there are some explanatory texts on larger screens.

plurals
  1. POZend_Db_Table and db->select in controller or model
    primarykey
    data
    text
    <p>I'm a little bit confused with Zend. Many examples show the usage of Zend_db_Table in the controller. But from what I've learn about MVC, anything about DB should be in the model. Now that Zend is created and maintain by PHP team, I really don't know what to think, so I follow the rule without asking.</p> <p>Here is an example of the kind of code I put in the controller for now.</p> <p>Thanks to anyone who could clarify my doubt.</p> <pre><code>$filter = $this-&gt;_getParam('filter', array()); $order_by = $this-&gt;_getParam('order_by', 'last_name'); $order = $this-&gt;_getParam('order', 'ASC'); // Select $db = Zend_Db_Table::getDefaultAdapter(); $select = $db-&gt;select('*')-&gt;from('contact_address'); // Filter / Where $where = array(); if(isset($filter['id']) AND $filter['id'] != ""){ $select-&gt;where('id = ?' , $filter['id']); } if(isset($filter['title']) AND $filter['title'] != ""){ $select-&gt;where('CONCAT(first_name, " ", last_name) LIKE ?', $filter['title'] . '%'); } if(isset($filter['phone']) AND preg_match_all('/\d/', $filter['phone'], $matches)){ $select-&gt;where('phone LIKE ?', implode('', $matches[0]) . '%'); } if(isset($filter['email']) AND $filter['email'] != ""){ $select-&gt;where('email LIKE ?', $filter['email'] . '%'); } if(isset($filter['published']) AND $filter['published'] != ""){ $select-&gt;where('published = ?', $filter['published']); } else{ $select-&gt;where('published &gt;= 0'); } // Order $select-&gt;order($order_by . ' ' . $order); $select-&gt;order('last_name ASC'); // Pagination $paginator = Zend_Paginator::factory($select); $paginator-&gt;setCurrentPageNumber($this-&gt;_getParam('page', 1)); $paginator-&gt;setItemCountPerPage($_SESSION['LIMIT_PER_PAGE']); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload