Skip to content

Instantly share code, notes, and snippets.

@davidcoallier
Created August 18, 2010 09:48
Show Gist options
  • Save davidcoallier/534198 to your computer and use it in GitHub Desktop.
Save davidcoallier/534198 to your computer and use it in GitHub Desktop.
<?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