Created
August 18, 2010 09:48
-
-
Save davidcoallier/534198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Default_Model_FooBar extends Zend_Db_Table_Abstract | |
{ | |
/** | |
* Local table name | |
* | |
* @var string $_name The name of the table associated with | |
* this model class. | |
*/ | |
protected $_name = 'foobar'; | |
/** | |
* Get Foo. | |
* | |
* This method does absolutely nothing real but | |
* would fetch "foo" using a like. | |
* | |
* @param string $bar The string to search like. | |
* @return array An array of results or false. | |
*/ | |
public function getFoo($bar) | |
{ | |
$select = $this->getSelect(); | |
// Magic is here! | |
$select->where('t.foo LIKE ?', $bar . '%'); | |
return $this->getAdapter()->query($select)->fetchAll(); | |
} | |
/** | |
* Get Foo OR bar. | |
* | |
* This method does absolutely nothing real but | |
* would fetch "foo" or "bar" using a like cond. | |
* | |
* @param string $bar The string to search like. | |
* @return array An array of results or false. | |
*/ | |
public function getFooBar($bar) | |
{ | |
$select = $this->getSelect(); | |
// Magic is here! | |
$select->where('t.foo LIKE ?', $bar . '%'); | |
$select->orWhere('t.bar LIKE ?', $bar . '%'); | |
return $this->getAdapter()->query($select)->fetchAll(); | |
} | |
/** | |
* Get a select | |
* | |
* Simple method to construct a common select and return it. | |
* | |
* @return Zend_Db_Select $select The select object. | |
*/ | |
protected function getSelect() | |
{ | |
$select = $this->getAdapter()->select(); | |
$select->from( | |
't' => $this->_name, array('fields', 'I', 'want') | |
); | |
return $select; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment