一级缓存 id
根据 id 获取缓存

@param string     $model 类名
@param string|int $id    主键

@return mixed
540237
public function recordCache($model, $id) {
        $cache_key = "record_" . $model . $id;
        $data = Cache::get($cache_key);
        if ($data) {
            Log::debug("命中缓存" . $model . " " . $id, 'cache');
            /* @var $record Record */
            $record = new $model;
            $record->fromDbData($data);
            return $record;
        }
        return null;
    }
989622
public function doDelete($model, $id)
    {
        if ($this->weak) {
            return;
        }

        $persistence = $this->persistence ?:
            $this->owner->persistence;

        $persistence->delete(
            $model,
            $this->id,
            $this->foreign_table
        );

        $this->id = null;
    }
415707
public function getById($id, $col = null)
    {
        $id = (int) $id;
        $model = $this->getCacheItem($id);

        if (!$model) {
            $model = $this->getMapper()->getById($id, $col);

            if ($this->useCache) {
                $this->setCacheItem($id, $model);
            }
        }

        return $model;
    }
977038
public function existsAndNotDeleted(Model $model, $id) {
		if ($id === null) {
			$id = $model->getID();
		}
		if ($id === false) {
			return false;
		}
		$exists = $model->find('count', array('conditions' => array($model->alias . '.' . $model->primaryKey => $id)));
		return ($exists ? true : false);
	}
651326
public function show($id)
    {
        $modelName = $this->modelFullName;
        $model = $modelName::find($id);
        if(!$model) throw new NotFoundException('There is no Resource with id = ' . $id . ' !');
        return $model;
    }
859806
public function detailsCreateDefaults(Model $Model, $id = null) {
		if (empty($Model->detailDefaults)) {
			return null;
		}

		$id = empty($id) ? $Model->getID() : $id;
		if (empty($id)) {
			throw new Exception();
		}

		$DetailModel = ClassRegistry::init($this->settings[$Model->alias]['alias']);

		$pos = 1;
		$data = array();
		foreach ($Model->detailDefaults as $record) {
			array_push($data, $record + array('foreign_key' => $Model->id, 'foreign_model' => $Model->className(), 'position' => $pos++));
		}

		if ($DetailModel->saveMany($data, array('validate' => false))) {
			return true;
		}

		return false;
	}
1043769
protected function findModel($id)
    {
        if (($model = Rubric::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException(Module::t('core', 'The requested model does not exist.'));
        }
    }
193218
protected function getAbstractId($id)
    {
        if (isset($this->aliases[$id])) {
            $id = $this->aliases[$id];
        }

        return $id;
    }
276568
public function undelete($model, $id) {
		$runtime = $this->runtime[$model->alias];
		$this->softDelete($model, false);

		$data = array();
		$fields = $this->_normalizeFields($model);
		foreach ($fields as $flag => $date) {
			if (true === $runtime || $flag === $runtime) {
				$data[$flag] = false;
				if ($date) {
					$data[$date] = null;
				}
				if ($flag === $runtime) {
					break;
				}
			}
		}

		$model->create();
		$model->set($model->primaryKey, $id);
		$result = $model->save(array($model->alias => $data), false, array_keys($data));
		$this->softDelete($model, $runtime);
		return $result;
	}
239342
protected function findModel($id)
    {
        $class = $this->modelClass;
        if (($model = $class::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
1373520
public function save($model, $id, $data)
    {
        if (is_null($id)) { // insert
            $model->data = $this->sendCollectionRequest($model, $this->insert_mode, $data);
            $model->id = $model->data ? $model->data[$model->id_field] : null;
        } else { // update
            $model->data = $this->sendItemRequest($model, $id, $this->update_mode, $data);
            $model->id = $model->data ? $model->data[$model->id_field] : null;
        }

        return $model->id;
    }
995988
static public function find($id)
    {
        $model = new static;
        $result = $model->execute('SELECT * FROM '.$model->table.' WHERE '.$model->key.' = ?', [$id]);
        if (is_array($result)) {
            $result = current($result);
        }
        return $result;
    }
526241
protected function findModel($id)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;
        $keys = $modelClass::primaryKey();
        if (count($keys) > 1) {
            $values = explode(',', $id);
            if (count($keys) === count($values)) {
                $model = $modelClass::findOne(array_combine($keys, $values));
            }
        } elseif ($id !== null) {
            $model = $modelClass::findOne($id);
        }

        if (isset($model)) {
            return $model;
        } else {
            throw new NotFoundHttpException("Object not found: '$id'");
        }
    }
994656
public function deleteById($id) : int
    {
        $sql = 'DELETE FROM `' . $this->table . '` WHERE ';

        // Assign ids
        if (is_array($id)) {
            $i = 0;
            foreach ($id as $_id) {
                if ($i === 0) {
                    $sql .= ' id=:id' . $i;
                } else {
                    $sql .= ' OR id=:id' . $i;
                }
                $i++;
            }
            $query = $this->pdo->prepare($sql);
            for ($j = 0; $j < 0; $j++) {
                $query->bindParam(':id' . $j, $id[$j]);
            }
        } else {
            $sql .= 'id=:id';
            $query = $this->pdo->prepare($sql);
            $query->bindParam(':id', $id);
        }

        $query->execute();

        return $query->rowCount();
    }
571923
public function getQuestion4Id($id)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->where('p.id = :id')
            ->setParameter('id', $id)
            ->getQuery();


        return $query->getOneOrNullResult();
    }
1075989
public function findModel($id)
    {
        $model = $this->findModelClassObject($this->modelClass, $id, 'view');
        
        if (!$model) {
            throw new NotFoundHttpException("Unable to find the Model for the given ID");
        }
        
        return $model;
    }
255096
public function getById($id)
    {
        $query = function () use ($id) {
            return $this->model
                ->with($this->requiredRelationships)
                ->find($id);
        };

        return $this->doQuery($query);
    }