Example #1
0
 /**
  * Ajax поиск пользователя по его ФИО.
  * @param string $search
  * @param string $value
  * @param string $colAlias
  * @return Json
  * */
 public function actionAjaxSearch($search = '', $value = '', $colAlias = 'title')
 {
     /** @var User $recordModel * */
     $recordModel = User::className();
     /** @var User $recordModelObject * */
     $table = $recordModel::tableName();
     $alias = $colAlias;
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new MultilingualQuery($recordModel);
         $query->select('*, CONCAT_WS(" → ", `name`, `email`) AS text')->from($table)->joinWith('profile');
         $query->where($alias . ' LIKE "%' . $search . '%"')->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         //            debug($data);
         $out['results'] = array_values($data);
     } elseif ($value > 0) {
         $out['results'] = ['id' => $value, 'text' => $recordModel::find($value)->{$colAlias}];
     }
     return Json::encode($out);
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(User::className(), ['id' => 'author_id']);
 }