Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = user::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'User'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'profileLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'Profile'], 'roleName' => ['asc' => ['role.role_name' => SORT_ASC], 'desc' => ['role.role_name' => SORT_DESC], 'label' => 'Role'], 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status'], 'userTypeName' => ['asc' => ['user_type.user_type_name' => SORT_ASC], 'desc' => ['user_type.user_type_name' => SORT_DESC], 'label' => 'User Type'], 'created_at' => ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC], 'label' => 'Created At'], 'email' => ['asc' => ['email' => SORT_ASC], 'desc' => ['email' => SORT_DESC], 'label' => 'Email']]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['role'])->joinWith(['status'])->joinWith(['profile'])->joinWith(['userType']);
         return $dataProvider;
     }
     $this->addSearchParameter($query, 'user.id');
     $this->addSearchParameter($query, 'username', true);
     $this->addSearchParameter($query, 'email', true);
     $this->addSearchParameter($query, 'role_id');
     $this->addSearchParameter($query, 'status_id');
     $this->addSearchParameter($query, 'user_type_id');
     $this->addSearchParameter($query, 'created_at');
     $this->addSearchParameter($query, 'updated_at');
     $query->joinWith(['role' => function ($q) {
         $q->where('role.role_name LIKE "%' . $this->roleName . '%"');
     }])->joinWith(['status' => function ($q) {
         $q->where('status.status_name LIKE "%' . $this->statusName . '%"');
     }])->joinWith(['userType' => function ($q) {
         $q->where('user_type.user_type_name LIKE "%' . $this->userTypeName . '%"');
     }]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = user::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\user;
/* @var $this yii\web\View */
/* @var $model frontend\models\Product */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="product-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'user_id')->dropDownlist(ArrayHelper::map(user::find()->all(), 'id', 'username'), ['prompt' => 'Select user']);
?>
   

    <?php 
echo $form->field($model, 'id')->textInput();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 45]);
?>

    <?php 
echo $form->field($model, 'description')->textInput(['maxlength' => 45]);
?>
    
Beispiel #4
0
 /**
  * Finds the user model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return user the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = user::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }