Esempio n. 1
0
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category 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.');
     }
 }
Esempio n. 2
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use SlamMT\shop\models\Category;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model SlamMT\shop\models\Product */
/* @var $form yii\widgets\ActiveForm */
$form = ActiveForm::begin();
// получаем всех категории
$category = Category::find()->all();
// формируем массив, с ключем равным полю 'id' и значением равным полю 'name'
$items = ArrayHelper::map($category, 'id', 'name');
//var_dump($items);
$params = ['prompt' => 'Укажите категорию'];
echo $form->field($model, 'category_id')->dropDownList($items, $params);
ActiveForm::end();
?>

<div class="product-form">

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

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

    <?php