コード例 #1
0
ファイル: _form.php プロジェクト: yagerguo/yii2-post-module
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yagerguo\yii2post\models\Category;
?>

<div class="post-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'categoryId')->dropDownList(['' => ''] + Category::dropDownData())->label('分类');
?>

    <?php 
echo $form->field($model, 'slug')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'status')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'content')->widget(\yii\redactor\widgets\Redactor::className());
コード例 #2
0
 /**
  * Finds the PostCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PostCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }