本文整理汇总了PHP中Model::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::findById方法的具体用法?PHP Model::findById怎么用?PHP Model::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::findById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeValidate
/**
* beforeValidate is called before a model is validated, you can use this callback to
* add behavior validation rules into a models validate array. Returning false
* will allow you to make the validation fail.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False or null will abort the operation. Any other result will continue.
* @see Model::save()
*/
public function beforeValidate(Model $model, $options = array())
{
//ページデータをセット
$referencePageId = $model->getReferencePageId($model->data);
$fields = array('room_id', 'permalink');
$targetPage = $model->findById($referencePageId, $fields);
if (empty($targetPage)) {
return false;
}
$model->data['Page']['room_id'] = Current::read('Room.id');
$slug = $model->data['Page']['slug'];
if (!isset($slug)) {
$slug = '';
}
$model->data['Page']['slug'] = $slug;
$permalink = '';
if (strlen($targetPage['Page']['permalink']) !== 0) {
$permalink = $targetPage['Page']['permalink'] . '/';
}
$permalink .= $slug;
$model->data['Page']['permalink'] = $permalink;
$model->data['Page']['is_published'] = true;
$model->data['Page']['is_container_fluid'] = false;
return parent::beforeValidate($model, $options);
}
示例2: findById
/**
* 根据id 查找数据,默认查找缓存
* @param int $id
* @param boolean $isCache
* @return array
*/
public function findById($id, $isCache = true)
{
if ($isCache == true) {
$dataList = $this->_getGlobalData($this->_tableName);
return $dataList[$id];
} else {
return parent::findById($id);
}
}
示例3: findById
/**
* 根据id查找指定的id
* @param int $id
* @param boolean $isCache
* @return array
*/
public function findById($id, $isCache = true)
{
if ($isCache == true) {
$serverList = $this->_getGlobalData('operator_list');
return $serverList[$id];
} else {
return parent::findById($id);
}
}
示例4: getUser
public static function getUser($id = null)
{
$db = new Model();
if ($id == null) {
$id = $_SESSION['uid'];
}
$user = $db->findById($id, 'users');
return self::instantiate($user);
}
示例5: findById
/**
* IDで検索(blog_pluginsのattribute属性付き
*/
public function findById($id, $options = array())
{
$plugin = parent::findById($id, $options);
if (!empty($plugin)) {
$plugin['title_align'] = $plugin['contents_align'] = 'left';
$plugin['title_color'] = $plugin['contents_color'] = '';
}
return $plugin;
}
示例6: hasDiffAddress
/**
* hasDiffAddress
* @param Model $model
* @return boolean
*/
protected function hasDiffAddress(Model $model)
{
$this->_instance = $model->findById($model->id);
if ($this->_instance !== null && isset($model->data['User']['live_country'])) {
$prevAddress = array('live_country' => $this->_instance['User']['live_country'], 'live_place' => $this->_instance['User']['live_place'], 'live_address' => $this->_instance['User']['live_address']);
$currentAddress = array('live_country' => $model->data['User']['live_country'], 'live_place' => $model->data['User']['live_place'], 'live_address' => $model->data['User']['live_address']);
$result = Hash::diff($prevAddress, $currentAddress);
return !empty($result) ? true : false;
}
return false;
}
示例7: beforeSave
public function beforeSave(Model $model, $options = array())
{
if (isset($this->options[$model->alias]['actions']['edit'])) {
$fields = array();
foreach ($this->options[$model->alias]['actions']['edit']['fields'] as $field => $options) {
$fields[] = $field;
}
$this->oldData = $model->findById($model->id, $fields);
}
return true;
}
示例8: beforeSave
/**
* Creates Old object and List of changed fields
* @param Model $Model
* @param array $options
* @return bool
*/
public function beforeSave($Model, $options)
{
$Model->recursive = -1;
$Model->old = $Model->findById($Model->id);
if ($Model->old) {
foreach ($Model->data[$Model->alias] as $key => $value) {
if ($Model->old[$Model->alias][$key] != $value) {
$Model->changed_fields[] = $key;
}
}
}
return true;
}
示例9: download
public function download(Model $model, $id)
{
$model->recursive = -1;
$data = $model->findById($id);
$fields = $this->settings[$model->alias];
$fileName = $data[$model->alias][$fields['name']];
$fileInfo = explode('.', $fileName);
$fileType = $fileInfo[count($fileInfo) - 1];
header('Content-type: ' . $fileType);
header('Content-Disposition: attachment; filename="' . $fileName . '"');
echo $data[$model->alias][$fields['content']];
exit;
}
示例10: onLogin
/**
* onLogin
* @param Model $model
* @return array $data
*/
protected function onLogin(Model $model)
{
$result = false;
$this->_instance = $model->findById($model->id);
if ($this->_instance !== null && (empty($this->_instance['User']['lat']) || empty($this->_instance['User']['lng']))) {
if (isset($model->data['User']['lat']) && !empty($model->data['User']['lat']) && isset($model->data['User']['lng']) && !empty($model->data['User']['lng'])) {
$result = $this->onExistLatLng($model->data['User']['lat'], $model->data['User']['lng']);
} else {
$result = $this->onIpProcess();
}
} else {
return array('lat' => $this->_instance['User']['lat'], 'lng' => $this->_instance['User']['lng']);
}
return $this->onProcessAddressResult($result);
}
示例11: array
/**
* Obtiene los grupos hijos del grupo al que el usuario loggeado pertenece, para obtener los prefijos a los que este usuario tiene permiso de edición.
* @return Array
* @TODO hacer que obtenga los hijos de la tabla de grupo como arbol
*/
function __getGroupPrefix()
{
//$groups=array();
$parent = array(Configure::read("loggedUser.User.group_id"));
$group = $this->Group->findById(Configure::read("loggedUser.User.group_id"), array('name'));
$groups = Set::extract("/Group/name", $group);
//pr($groups);
while (!empty($parent)) {
$recordset = $this->Group->find("all", array('conditions' => array('Group.parent_id' => $parent), 'fields' => array('Group.id', "Group.name")));
$childrenName = Set::extract("/Group/name", $recordset);
if (!empty($childrenName)) {
$groups = am($groups, $childrenName);
}
$parent = Set::extract("/Group/id", $recordset);
}
#while(!empty($parent));
#pr($groups);
return $groups;
}
示例12: beforeValidate
public function beforeValidate(Model $model, $options = array())
{
if (!array_key_exists('id', $model->data[$model->alias]) || !$model->data[$model->alias]['id']) {
if (!isset($model->id) || !$model->id) {
return true;
}
$model->data[$model->alias]['id'] = $model->id;
}
if (!array_key_exists('opt_' . $this->config['field'], $model->data[$model->alias]) || !$model->data[$model->alias]['opt_' . $this->config['field']]) {
throw new RuntimeException(__d('optimistic_lock', 'Field %s doesn\'t appear in the post request.', $this->config['field']));
}
if ($currentRecord = $model->findById($model->data[$model->alias]['id'])) {
if ($model->data[$model->alias]['opt_' . $this->config['field']] != $currentRecord[$model->alias][$this->config['field']]) {
$model->validationErrors[$this->config['field']] = $this->config['message'];
return false;
}
}
unset($model->data[$model->alias]['opt_' . $this->config['field']]);
return true;
}
示例13: beforeSave
public function beforeSave(Model $model, $options = array())
{
if (isset($model->data[$model->name][$this->settings[$model->name]['label']])) {
extract($this->settings[$model->name]);
$attachment = $model->data[$model->name][$label];
if (!empty($attachment['name'])) {
//====defining names for our database columns and also giving unique name for each attachment====//
$model->data[$model->name][$fields['filename']] = $this->_fileExists($this->_attachmentRoot . $attachment['name']) ? time() . '_' . $attachment['name'] : $attachment['name'];
//====checking all the conditions before uploading and saving====//
if (!$this->_isUploaded($attachment) || !$this->_isValidSize($attachment['size']) || !$this->_isValidType($attachment) || !$this->_dirExists($this->_attachmentRoot) || !$this->_moveUploaded($attachment['tmp_name'], $model->data[$model->name][$fields['filename']])) {
$model->validationErrors[$label] = $this->_errorMsg;
return false;
}
//====if the file type is image/jpeg====//
if (in_array($attachment['type'], $this->_validThumbTypes)) {
list($width, $height) = getimagesize($this->_attachmentRoot . $model->data[$model->name][$fields['filename']]);
if (isset($this->settings[$model->name]['thumbnails'])) {
//====resizing the images and saving them to different location====//
foreach ($this->settings[$model->name]['thumbnails'] as $dir => $size) {
list($width, $height) = explode('x', strtolower($size));
if ($this->_dirExists($this->_attachmentRoot . $dir)) {
$this->_resizeToThumb($model->data[$model->name][$fields['filename']], $dir, $width, $height);
}
}
}
}
} else {
if ($model->id > 0) {
$record = $model->findById($model->id);
if (!empty($record[$model->name][$fields['filename']])) {
$model->data[$model->name][$fields['filename']] = $record[$model->name][$fields['filename']];
} else {
$model->data[$model->name][$fields['filename']] = '';
}
} else {
$model->data[$model->name][$fields['filename']] = '';
}
}
}
return true;
}
示例14: findById
/**
* 根据ID查找记录
* @param int $id
*/
public function findById($id, $isCache = TRUE)
{
if ($isCache) {
$serverList = $this->_getGlobalData('gameser_list');
return $serverList[$id];
} else {
return parent::findById($id);
}
}
示例15: beforeDelete
/**
* After delete
* 画像ファイルの削除を行う
* 削除に失敗してもデータの削除は行う
*
* @param Model $model
* @return void
* @access public
*/
function beforeDelete(&$model)
{
$model->data = $model->findById($model->id);
$this->delFiles($model);
}