/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Persons::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(['person_id' => $this->person_id, 'organization_id' => $this->organization_id, 'created' => $this->created]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'photo_filepath', $this->photo_filepath])->andFilterWhere(['like', 'state', $this->state]); return $dataProvider; }
<?php use yii\grid\GridView; use yii\helpers\Html; use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $model app\models\Organizations */ /* @var $searchModel app\models\PersonsSearch */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => 'Organizations', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $personsDataProvider = new \yii\data\ActiveDataProvider(['query' => \app\models\Persons::find()->where(['organization_id' => Yii::$app->getRequest()->getQueryParam('id')]), 'pagination' => ['pageSize' => 20]]); ?> <div class="organizations-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->organization_id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->organization_id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['organization_id', 'name', 'address', 'city', 'postal_code', 'website', 'description:ntext', 'logo_filepath', 'state']]);
/** * @return \yii\db\ActiveQuery */ public function getPersons() { return $this->hasMany(Persons::className(), ['organization_id' => 'organization_id']); }
/** * @return \yii\db\ActiveQuery */ public function getPerson() { return $this->hasOne(Persons::className(), ['person_id' => 'person_id']); }
/** * Finds the Persons model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Persons the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Persons::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }