/**
  * @param null $nullOption
  * @return array|null
  */
 public static function selector($nullOption = null)
 {
     $out = ContentSections::find()->select('name')->indexBy('id')->column();
     if ($nullOption) {
         $out = $nullOption + $out;
     }
     return $out;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ContentSections::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #3
0
        <?php 
echo $form->field($model, 'name', ['template' => '<div class="col-lg-5">{input}</div>', 'options' => ['class' => 'inline']])->textInput(['maxlength' => true]);
?>

        <?php 
echo $form->field($model, 'slug', ['template' => '<div class="col-lg-5">{input}</div>', 'options' => ['class' => 'inline']])->textInput(['maxlength' => true]);
?>
    </div>

    <div class="form-group row">
        <div class="col-lg-2 small"><?php 
echo Yii::t('main', 'Rubric');
?>
</div>
        <?php 
echo $form->field($model, 'section_id', ['template' => '<div class="col-lg-4">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList(ContentSections::selector());
?>

        <?php 
echo $form->field($model, 'rubric_id', ['template' => '<div class="col-lg-4">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList(ContentRubrics::selector($model->section_id));
?>

        <?php 
echo $form->field($model, 'content_type', ['template' => '<div class="col-lg-2">{input}</div>', 'options' => ['class' => 'inline']])->dropDownList($model->contentTypes);
?>

    </div>

    <?php 
if ($model->content_type == 'javascript') {
    echo $form->field($model, 'text')->widget(CodemirrorWidget::class, ['preset' => 'javascript', 'assets' => [CodemirrorAsset::MODE_CLIKE, CodemirrorAsset::KEYMAP_EMACS, CodemirrorAsset::ADDON_EDIT_MATCHBRACKETS, CodemirrorAsset::ADDON_COMMENT, CodemirrorAsset::ADDON_DIALOG, CodemirrorAsset::ADDON_SEARCHCURSOR, CodemirrorAsset::ADDON_SEARCH], 'options' => ['rows' => 20], 'settings' => ['mode' => 'javascript']]);
 /**
  * Finds the ContentSections model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ContentSections the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ContentSections::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }