find() public method

This method accepts a variable number of arguments. If the table has a multi-column primary key, the number of arguments must be the same as the number of columns in the primary key. To find multiple rows in a table with a multi-column primary key, each argument must be an array with the same number of elements. The find() method always returns a Rowset object, even if only one row was found.
public find ( ) : Zend_Db_Table_Rowset_Abstract
return Zend_Db_Table_Rowset_Abstract Row(s) matching the criteria.
示例#1
0
 public function find($id)
 {
     $result = $this->dbTable->find($id);
     if (0 == count($result)) {
         return false;
     }
     $row = $result->current();
     return array('id' => $row->id, 'state' => $row->state, 'info' => $row->info, 'lastupdate' => $row->lastupdate, 'sticked' => $row->sticked);
 }
示例#2
0
 public function get($_id)
 {
     $resultRet = $this->dbTable->find($_id);
     $enreg = $resultRet->current();
     if ($enreg === null) {
         return null;
     }
     $modelClassName = 'Application_Model_' . $this->className;
     $result = new $modelClassName();
     $result->fromArray($enreg);
     return $result;
 }
示例#3
0
 /**
  * Delete Entry
  *
  * @param Postr_Model_Entry $entry
  * @return Postr_Model_EntryMapper          Provides a fluent interface
  */
 public function deleteEntry(Postr_Model_Entry $entry)
 {
     $dbAdapter = $this->_entryTable->getAdapter();
     $dbAdapter->beginTransaction();
     $entryRow = $this->_entryTable->find($entry->getId())->current();
     $entryRow->delete();
     $dbAdapter->commit();
     return $this;
 }
示例#4
0
 /**
  * Returns the first row of the find query
  *
  * @param Integer|Array $primary
  * @return Zend_Db_Table_Row
  */
 public function get($pk)
 {
     // If the Primary Key is an Array
     if (is_array($pk)) {
         // Call the parent's find method with dynamic amount of parameters
         return call_user_func_array(array($this, 'find'), $pk)->current();
     }
     // The primary Key Is a single column
     return parent::find($pk)->current();
 }
示例#5
0
 public function getAttribute($id)
 {
     if (isset($this->_attributes[$id])) {
         return $this->_attributes[$id];
     } elseif (is_numeric($id)) {
         $attribute = $this->_attributeModel->find($id)->current();
     } else {
         $where = $this->_attributeModel->select()->where($this->_attributeFieldName . ' = ?', $id);
         $attribute = $this->_attributeModel->fetchRow($where);
     }
     $this->cacheAttribute($attribute);
     return $attribute;
 }
示例#6
0
 public function find($id)
 {
     $frontendOptions = array('lifetime' => 60 * 60 * 24, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => APPLICATION_CACHE_PATH);
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     $row = null;
     if ($cache->test('role_' . $id)) {
         $row = $cache->load('role_' . $id);
     } else {
         $row = parent::find($id)->current();
         $cache->save($row, 'role_' . $row->id);
     }
     return $row;
 }
示例#7
0
 /**
  * Overwrite the find method to get relations too.
  *
  * @return Phprojekt_ActiveRecord_Abstract An instance of Phprojekt_ActiveRecord_Abstract.
  */
 public function find()
 {
     $args = func_get_args();
     if (1 > count($args)) {
         throw new Phprojekt_ActiveRecord_Exception('Missing argument');
     }
     if (1 < count($args)) {
         throw new Phprojekt_ActiveRecord_Exception('Too many arguments');
     }
     if (is_null($args[0])) {
         throw new Phprojekt_ActiveRecord_Exception('Argument cannot be NULL');
     }
     $find = parent::find($args[0]);
     if (false === is_array($find) || count($find) === 0) {
         return $find;
     }
     $find = $find[0];
     // Reset data as all our relatios, etc stuff has to
     // deal with a new id
     $this->_data = array();
     $this->_storedId = null;
     foreach ((array) $find->_data as $col => $value) {
         $this->_data[self::convertVarFromSql($col)] = $value;
     }
     unset($find);
     if (!array_key_exists('id', $this->_data)) {
         throw new Phprojekt_ActiveRecord_Exception('Table must have an id');
     }
     $this->_storedId = $this->_data['id'];
     $this->_originalData = $this->_data;
     return $this;
 }
 /**
  * 扩充了父类的同名方法,如果传入的是整形值或整数字符串,则取得主键值为该整形值的所有记录。
  * 
  * @param  mixed $key The value(s) of the primary keys.
  * @return ZtChart_Model_Db_Table_Rowset Row(s) matching the criteria.
  */
 public function find()
 {
     if (1 == func_num_args()) {
         $primary = func_get_arg(0);
         if ($this->_isInt($primary)) {
             return parent::find(intval($primary));
         }
     }
     return call_user_func_array(array('parent', 'find'), func_get_args());
 }