/** * function ::create ($data) */ public static function create($data) { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = new RedirectUrl(); if ($model->load($data)) { if ($log = new UserLog()) { $log->username = $username; $log->action = 'Create'; $log->object_class = 'RedirectUrl'; $log->created_at = $now; $log->is_success = 0; $log->save(); } $model->created_by = $username; $model->created_at = $now; $from_urls_arr = explode("\n", str_replace("\r", "", $model->from_urls)); foreach ($from_urls_arr as &$item) { $item = trim($item); } $model->from_urls = json_encode($from_urls_arr); if ($model->save()) { if ($log) { $log->object_pk = $model->id; $log->is_success = 1; $log->save(); } return $model; } $model->getErrors(); return $model; } return false; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RedirectUrl::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => 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; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'is_active' => $this->is_active, 'status' => $this->status]); $query->andFilterWhere(['like', 'from_urls', $this->from_urls])->andFilterWhere(['like', 'to_url', $this->to_url])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]); return $dataProvider; }
/** * Finds the RedirectUrl model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return RedirectUrl the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = RedirectUrl::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }