本文整理汇总了PHP中waModel::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP waModel::getById方法的具体用法?PHP waModel::getById怎么用?PHP waModel::getById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waModel
的用法示例。
在下文中一共展示了waModel::getById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doLoad
/**
* Called by $this->load() to populate data into $this->persistent->rec_data
*
* Subclasses may override this method to tune load() behavior, e.g.
* to load data lazily by field name passed in $field_or_db_row.
* Subclasses overriding this should also call parent::doLoad() since the base class
* uses it to load data from $this->m model.
*
* @param array $field_or_db_row see $this->load()
* @throws waException
*/
protected function doLoad($field_or_db_row = null)
{
// load from array?
if (is_array($field_or_db_row)) {
$fields = $this->m->getMetadata();
$nulls = array_fill_keys(array_keys($fields), null);
$this->persistent->setAll(array_intersect_key($field_or_db_row, $fields) + $nulls);
return;
}
// requested field already loaded?
if ($field_or_db_row) {
// check if can be loaded from $this->m model
if (!array_key_exists($field_or_db_row, $this->m->getMetadata())) {
return;
}
} else {
$loaded = true;
foreach ($this->m->getMetadata() as $f => $v) {
if (!$this->persistent->keyExists($f)) {
$loaded = false;
break;
}
}
if ($loaded) {
return;
}
}
// load from model
$row = $this->m->getById($this->id);
if (!$row) {
throw new waException('No record found in ' . $this->m->getTableName() . ' for id=' . $this->id, 404);
}
$this->persistent->setAll($row);
}
示例2: getById
public function getById($value)
{
$data = parent::getById($value);
if ($data && $data['system_id'] && wa()->appExists($data['system_id'])) {
$app = wa()->getAppInfo($data['system_id']);
$data['name'] = $app['name'];
$data['icon'] = wa()->getRootUrl(true) . $app['icon'][16];
}
return $data;
}
示例3: getById
/**
* Returns data from table record with specified value in id field ($this->id).
*
* @param int|array $value Field value or array of values
* @return array|null
*/
public function getById($value)
{
if ($cache = wa()->getCache()) {
$cache_key = 'block_' . $value;
$result = $cache->get($cache_key);
if (!$result) {
$result = parent::getById($value);
if ($result) {
$cache->set($cache_key, $result, 86400);
}
}
return $result;
} else {
return parent::getById($value);
}
}