Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::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]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Exemple #2
0
<?php

use dosamigos\ckeditor\CKEditor;
use obuhovski\blog\models\Category;
use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model obuhovski\blog\models\Post */
/* @var $form yii\widgets\ActiveForm */
$categoriesList = Category::find()->select('name, id')->where(['status' => 1])->indexBy('id')->asArray()->column();
?>

<div class="post-form">

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

    <img class="img-responsive" src="<?php 
echo $model->getThumbUploadUrl('image');
?>
" alt="" />
    <?php 
echo $form->field($model, 'image')->fileInput();
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>
 public function init()
 {
     parent::init();
     $categories = Category::find()->where(['status' => 1])->with('posts')->all();
     echo $this->render('categories', ['categories' => $categories]);
 }