Beispiel #1
0
use yii\helpers\ArrayHelper;
use common\components\helpers\General;
use common\models\cms\CmsClass;
use yii\base\Object;
/* @var $this yii\web\View */
/* @var $model common\models\cms\CmsClass */
/* @var $form yii\widgets\ActiveForm */
if ($model->isNewRecord) {
    $model->status = true;
    $model->order = 10;
}
//指定了父级栏目
if (isset($id) && $id !== false) {
    $model->parent_id = $id;
}
$parentIds = ArrayHelper::merge(['0' => Yii::t('cms', 'Top Class')], ArrayHelper::map(General::recursiveObj(CmsClass::find()->orderBy(['order' => SORT_ASC])->all()), 'id', 'name'));
?>

<div class="row cms-class-form">
    <div class="col-md-1"></div>
    <div class="col-md-12 col-lg-6">
        <?php 
$form = ActiveForm::begin();
?>
        
        <?php 
echo $form->field($model, 'type')->dropDownList((new CmsClass())->cmsType);
?>
        
        <?php 
echo $form->field($model, 'parent_id')->dropDownList($parentIds);
Beispiel #2
0
 /**
  * 一对一
  */
 public function getCmsClass()
 {
     return $this->hasOne(CmsClass::className(), ['id' => 'cms_class_id']);
 }
Beispiel #3
0
 /**
  * Finds the CmsClass model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CmsClass the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CmsClass::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }