本文整理汇总了PHP中Dao::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP Dao::findById方法的具体用法?PHP Dao::findById怎么用?PHP Dao::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dao
的用法示例。
在下文中一共展示了Dao::findById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findById
/**
* Get a single instance of an entity by its database record id
*
* @param int $id The id of the entity
*
* @return BaseEntityAbstract
*/
public function findById($id)
{
$results = Dao::findById($this->_query->setSelectActiveOnly(false), $id);
$this->resetQuery();
return $results;
}
示例2: loadManyToOne
/**
* Lazy load a many-to-one relationship
*
* @param string $property The property that we are trying to load
*
* @return BaseEntityAbstract
*/
protected function loadManyToOne($property)
{
$this->__loadDaoMap();
if (is_null($this->{$property})) {
//if the proerty is allow to have null value, then let it be
if (DaoMap::$map[strtolower(get_class($this))][$property]['nullable']) {
$this->{$property} = null;
return $this;
}
//if the property is one of these, as when we are trying to save them, we don't have the iniated value
if (in_array($property, array('createdBy', 'updatedBy'))) {
$this->{$property} = Core::getUser();
} else {
throw new Exception('Property (' . get_class($this) . '::' . $property . ') must be initialised to integer or proxy prior to lazy loading.', 1);
}
}
// Load the DAO map for this entity
$cls = DaoMap::$map[strtolower(get_class($this))][$property]['class'];
if (!$this->{$property} instanceof BaseEntityAbstract) {
throw new DaoException('The property(' . $property . ') for "' . get_class($this) . '" is NOT a BaseEntity!');
}
$qry = new DaoQuery($cls);
$qry->setSelectActiveOnly(false);
$this->{$property} = Dao::findById($qry, $this->{$property}->getId());
return $this;
}