/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categorias::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(['idCate' => $this->idCate]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre]);
     return $dataProvider;
 }
Exemple #2
0
 /**
  * Lists all Categorias models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Categorias::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
<div class="productos-form">

 <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

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

    <?php 
echo $form->field($model, 'imagen')->fileInput();
?>
    
    <?php 
$categorias = ArrayHelper::map(Categorias::find()->all(), 'idCate', 'nombre');
echo $form->field($model, 'idCat')->dropDownList($categorias)->label('Categoría');
?>
	<div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
			<?php 
ActiveForm::end();
?>
</div>


Exemple #4
0
 public function actionAddproducts($id)
 {
     $model = $this->findModel($id);
     if (!$model->load(Yii::$app->request->post())) {
         //Obtengo los id de los productos en la tienda $id
         $ProductoTiendaModel = new ProductoTienda();
         $Productos = $ProductoTiendaModel->getAllProductos($id);
         $ProductosId = [];
         foreach ($Productos as $key => $value) {
             array_push($ProductosId, $value['idproducto']);
         }
         //Obtengo todos los productos y los separo en 2 arreglos
         $ProductosEnTienda = [];
         $RestoProductos = [];
         $TodosLosProductos = Producto::find()->where('idcategoria = 1')->all();
         foreach ($TodosLosProductos as $key => $value) {
             if (in_array($value['id'], $ProductosId)) {
                 array_push($ProductosEnTienda, $value);
             } else {
                 array_push($RestoProductos, $value);
             }
         }
         $productos = new ArrayDataProvider(['allModels' => $ProductosEnTienda]);
         $resto = new ArrayDataProvider(['allModels' => $RestoProductos]);
         return $this->render('addProducts', ['model' => $model, 'productos' => $productos, 'resto' => $resto, 'categorias' => ArrayHelper::map(Categorias::find()->All(), 'id', 'nombre')]);
     }
 }
Exemple #5
0
/* @var $model backend\models\Producto */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="producto-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

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

    <?php 
echo $form->field($model, 'idcategoria')->dropDownList(ArrayHelper::map(Categorias::find()->All(), 'id', 'nombre'));
?>

    <?php 
if (Yii::$app->controller->action->id === 'create') {
    ?>
    	<?php 
    echo $form->field($img_model, 'imageFile')->fileInput(['multiple' => false, 'accept' => 'image/*']);
    ?>
    <?php 
}
?>
 

    <div class="form-group">
        <?php