public function actionTmp() { $model = Question::find()->one(); $model->attributes = ['title' => 123]; $diff = new \cogpowered\FineDiff\Diff(); if (!isset($model->dirtyAttributes)) { $old = []; $new = $model->attributes; } else { $old = array_intersect_key($model->oldAttributes, $model->dirtyAttributes); $new = array_intersect_key($model->attributes, $model->dirtyAttributes); } echo $diff->render(json_encode($old), json_encode($new)); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'type' => $this->type, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Gets the last poll related to this pull request * @return Question */ public function getPoll() { if (static::$_polls === null) { static::$_polls = Question::find()->where(['like', 'relation_id', get_class($this)])->indexBy('relation_id')->all(); } return @static::$_polls[ModelHelper::getRelationId($this)]; }