/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AdCategory::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]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\ActiveForm; use common\models\User; use common\models\AdCategory; /* @var $this yii\web\View */ /* @var $model common\models\Advs */ /* @var $form yii\widgets\ActiveForm */ $authors = User::find()->all(); $items = ArrayHelper::map($authors, 'id', 'username'); $params = ['prompt' => 'Укажите автора']; $category = AdCategory::find()->all(); $categoryItem = ArrayHelper::map($category, 'id', 'title'); $categoryParams = ['prompt' => 'Укажите категорию']; ?> <div class="advs-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'anons')->textarea(['rows' => 3]); ?>
/** * @return \yii\db\ActiveQuery */ public function getSubDir() { $count = \common\models\AdCategory::find()->where(['category' => 1])->groupBy('ad_id')->count(); $count = floor($count / 1000); return $count; }