/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = FriendsLinks::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category' => $this->category, 'sort' => $this->sort, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\DetailView; use common\models\FriendsLinks; /* @var $this yii\web\View */ /* @var $model common\models\FriendsLinks */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'Friends Links'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="friends-links-view"> <p> <?php echo Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary btn-flat']); ?> <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger btn-flat', 'data' => ['confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['name', 'url:url', ['attribute' => 'category', 'value' => ArrayHelper::getValue(FriendsLinks::getCategory(), $model->category)], 'description', 'slug', 'sort', 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'status', 'value' => FriendsLinks::STATUS_IN_USE == $model->status ? Yii::t('common', 'In Use') : Yii::t('common', 'Not Used')]]]); ?> </div>
echo $form->field($model, 'url')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'category')->dropDownList($model->getCategory(), ['prompt' => '']); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'sort')->textInput(['value' => FriendsLinks::ORDER_DEFAULT]); ?> <?php echo $form->field($model, 'status')->dropDownList(FriendsLinks::getStatus()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
public static function getLinks() { return FriendsLinks::find()->where(['status' => FriendsLinks::STATUS_IN_USE])->all(); }
/** * Finds the FriendsLinks model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return FriendsLinks the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = FriendsLinks::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\grid\GridView; use common\models\FriendsLinks; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\FriendsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('common', 'Friends Links'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="friends-links-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => Yii::t('common', 'Friends Links')]), ['create'], ['class' => 'btn btn-primary btn-flat']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'url:url', ['attribute' => 'category', 'value' => function ($model) { return ArrayHelper::getValue(FriendsLinks::getCategory(), $model->category); }, 'filter' => FriendsLinks::getCategory()], 'created_at:datetime', ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('common', 'Not Used'), Yii::t('common', 'In Use')]], ['class' => 'yii\\grid\\ActionColumn']], 'layout' => "{items}\n{summary}\n{pager}"]); ?> </div>