记录并获取项目点击数
@param string $model 模型名称
@param string $model_id 模型ID
@param int $increasing 递增数量，默认是1
@return static
16411
public static function hit($model, $model_id, $increasing = 1)
    {
        if (($model = static::findOne(['model' => $model, 'model_id' => $model_id])) == null) {
            $model = new static();
        }
        $model->views = $model->views + $increasing;
        //昨日显示次数
        $model->yesterday_views = (date('Ymd', $model->updated_at) == date('Ymd', strtotime('-1 day'))) ? $model->day_views : $model->yesterday_views;
        $model->day_views = (date('Ymd', $model->updated_at) == date('Ymd', time())) ? ($model->day_views + $increasing) : 1;
        $model->week_views = (date('YW', $model->updated_at) == date('YW', time())) ? ($model->week_views + $increasing) : 1;
        $model->month_views = (date('Ym', $model->updated_at) == date('Ym', time())) ? ($model->month_views + $increasing) : 1;
        $model->save();
        return $model;
    }
226320
private function findModel($model_name, $id = null)
    {
        $model = config('kregel.warden.models.'.$model_name.'.model');
        if (empty($model)) {
            throw new \Exception('There is no model by the name {'.$model_name.'}');
        }
        if (empty($id) | !is_numeric($id)) {
            return new $model();
        }

        return $model::findOrFail($id);
    }
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;
    }
670530
public function createFromModel(Model $model)
    {
        $this->model = $model;
        $this->query = $this->model->newQuery();

        return $this;
    }
193582
public function asNode(Model $model)
    {
        $node = $this->client->makeNode();

        // If the key name of the model is 'id' we will need to set it properly with setId()
        // since setting it as a regular property with setProperty() won't cut it.
        if ($model->getKeyName() == 'id')
        {
            $node->setId($model->getKey());
        }

        // In this case the dev has chosen a different primary key
        // so we use it insetead.
        else
        {
            $node->setProperty($model->getKeyName(), $model->getKey());
        }

        return $node;
    }
719215
protected function getModelInstanceQuery(Model $model)
    {
        $query = $model->query();

        $this->applyOrderingToModelInstanceQuery($query);
        $this->applyStartAndStopLimitsToQuery($query);

        return $query;
    }
1271137
public function loadModel($id, $model = false)
    {
        if (!$model)
            $model = str_replace('Controller', '', get_class($this));
        if ($this->_loadModel === null) {
            $this->_loadModel = CActiveRecord::model($model)->findbyPk($id);
            if ($this->_loadModel === null)
                throw new CHttpException(404, Yii::t('email', 'The requested page does not exist.'));
        }
        return $this->_loadModel;
    }
361626
function(model) {
    if (!model.id) {
      model.id = guid();
      model.set(model.idAttribute, model.id);
    }
    this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));
    this.records.push(model.id.toString());
    this.save();
    return this.find(model);
  }
221381
public function getVersionModel($version_id)
    {
        $version = $this->versions()->where("version_id", "=", $version_id)->first();
        if (!is_null($version)) {
            return $version->getModel();
        }
        return null;
    }
1230500
private function makeTemplate($sub_directories, $pre_model_path, $model, $no_get_id)
    {
        $file = __DIR__ . "/../templates/model/";
        $file .= $no_get_id ? "model.php.dist" : "model-with-get-id.php.dist";

        if (file_exists($file))
        {
            $template = strtr(file_get_contents($file), [
                '{{namespace}}' => get_app_namespace(),
                '{{sub_directories}}' => $sub_directories,
                '{{model}}' => $model
            ]);

            $file_path = "{$pre_model_path}/{$model}.php";

            $file = fopen($file_path, "w");
            fwrite($file, $template);
            fclose($file);

            return file_exists($file_path);
        }

        return false;
    }
396452
public function hasMany($model, $foreignKey = '', $localKey = '')
    {
        // 记录当前关联信息
        $model      = $this->parseModel($model);
        $localKey   = $localKey ?: $this->getPk();
        $foreignKey = $foreignKey ?: $this->getForeignKey($this->name);

        return new HasMany($this, $model, $foreignKey, $localKey);
    }
1272155
@PutAction("{model}")
    public void update(@DbBind MODEL_TYPE model, MODEL_TYPE data) {
        $.merge(data).filter("-id").to(model);
        dao.save(model);
    }
1129534
public function clearCache(Model $model) {
        if ($this->_cached) {
            foreach ($this->_cached as $key => $value) {
                $this->deleteCache($model, $key);
            }
        }

        return Cache::clear(false, $this->settings[$model->alias]['cacheConfig']);
    }
634889
protected function createModel($model_name)
    {
        $this->post('warden::api.create-model', [$model_name]);

        return redirect(route('warden::model', [$model_name, $model->id]));
    }
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);
	}
824840
public static function instance($model_class)
	{
		$observer = get_called_class();
		if (empty(static::$_instances[$observer][$model_class]))
		{
			static::$_instances[$observer][$model_class] = new static($model_class);
		}

		return static::$_instances[$observer][$model_class];
	}
3335
private function doCommitCreate(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preCreate, $model);

        $this->getPersisterFor($model->getType())->create($model);
        $model->getState()->setNew(false);
        // Should the model always reload? Or should the commit be assumed correct and just clear the new/dirty state?
        $model->reload();

        $this->dispatchLifecycleEvent(Events::postCreate, $model);
        return $model;
    }