Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Brand::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]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBrandRelation()
 {
     return $this->hasOne(Brand::className(), ['id' => 'brand_id']);
 }
Ejemplo n.º 3
0
 /**
  * Finds the Brand model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Brand the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Brand::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 4
0
use im\forms\components\ContentBlock;
use im\forms\components\FieldSet;
use im\forms\components\Tab;
use im\forms\components\TabSet;
use im\tree\widgets\JsTreeInput;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model im\catalog\models\Product */
/* @var $form yii\widgets\ActiveForm */
?>

<?php 
$form = ActiveForm::begin(['fieldClass' => 'im\\forms\\widgets\\ActiveField', 'options' => ['enctype' => 'multipart/form-data']]);
?>

<?php 
echo new FieldSet('product', [new TabSet('tabs', [new Tab('main', Module::t('product', 'Main'), [$form->field($model, 'sku')->textInput(['maxlength' => true]), $form->field($model, 'title')->textInput(['maxlength' => true]), $form->field($model, 'slug')->textInput(['maxlength' => true]), $form->field($model, 'description')->textarea(['maxlength' => true]), $form->field($model, 'brand_id')->dropDownList(ArrayHelper::map(Brand::find()->asArray()->orderBy('name')->all(), 'id', 'name'), ['prompt' => '']), $form->field($model, 'price')->textInput(), $form->field($model, 'status')->dropDownList($model::getStatusesList())]), new Tab('attributes', Module::t('product', 'Attributes'), [new ContentBlock('attributes', $this->render('_attributes', ['model' => $model, 'form' => $form]))], $form, $model), new Tab('categories', Module::t('product', 'Categories'), [$form->field($model, 'categories')->widget(JsTreeInput::className(), ['apiOptions' => ['rootsUrl' => Url::to(['/api/v1/product-categories/roots']), 'childrenUrl' => Url::to(['/api/v1/product-categories/{id}/children']), 'parentsUrl' => Url::to(['/api/v1/product-categories/{id}/ancestors']), 'attributesMap' => ['id' => 'id', 'text' => 'name', 'children' => 'hasChildren', 'str' => 'string']]])]), new Tab('images', Module::t('product', 'Images'), [$form->field($model, 'uploadedImages[]', ['enableClientValidation' => false])->fileInput(['multiple' => true, 'accept' => 'image/*']), new ContentBlock('images_list', $this->render('_images', ['model' => $model, 'form' => $form]))])])]);
?>

<?php 
echo Html::submitButton($model->isNewRecord ? Module::t('module', 'Create') : Module::t('module', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-success']);
?>

<?php 
ActiveForm::end();
?>