/** * 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; }
/** * Finds the Categorias model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Categorias the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Categorias::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $this yii\web\View */ /* @var $model backend\models\Producto */ $this->title = Yii::t('app', 'Update picture of {modelClass}: ', ['modelClass' => 'product']) . ' ' . $model->Nombre; $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Products'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->Nombre, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); ?> <div class="producto-update"> <h1><?php echo Html::encode($this->title); ?> </h1> </br> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['Nombre', ['attribute' => 'idcategoria', 'value' => Categorias::findOne($model->idcategoria)->nombre]]]); ?> <div class="producto-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'Nombre')->hiddenInput()->label(false); ?> <?php echo $form->field($model, 'idcategoria')->hiddenInput()->label(false); ?>
/** * @return \yii\db\ActiveQuery */ public function getIdcategoria0() { return $this->hasOne(Categorias::className(), ['id' => 'idcategoria']); }
<?php use yii\helpers\Html; use yii\grid\GridView; use backend\models\Categorias; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Products'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="producto-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Yii::t('app', 'Create product'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'Nombre', ['attribute' => 'idcategoria', 'value' => function ($producto) { return Categorias::findOne($producto->idcategoria)->nombre; }], 'Imagen', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use backend\models\Categorias; use yii\helpers\ArrayHelper; use yii\grid\GridView; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model backend\models\Comercios */ $this->title = Yii::t('app', 'Add products to ') . $model->nombre; $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'shop'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $nombreColumna = function ($data) { return Categorias::findOne($data->idcategoria)->nombre; }; ?> <div class="comercios-view"> <h1><?php echo Html::encode($this->title); ?> </h1> </br> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'nombre')->dropDownList($categorias, ['onchange' => ' $.post( "' . Url::toRoute('/comercios/getproductos') . '", { id: $(this).val(),idcomercio:' . $model->id . ' } ) .done(function( data ) {
public function actionRemove_product() { $ProductoTiendaModel = new ProductoTienda(); if ($ProductoTiendaModel->load(Yii::$app->request->post())) { $producto = Producto::find()->where(['id' => $ProductoTiendaModel->idproducto])->one(); $categoria = Categorias::findOne($producto->idcategoria); $ProductoTienda = ProductoTienda::find()->where(['idproducto' => $ProductoTiendaModel->idproducto, 'idcomercio' => $ProductoTiendaModel->idcomercio])->one(); $ProductoTienda->delete(); $tooltip = Yii::t('app', 'Click to add'); $message = ['id' => $producto->id, 'nombre' => $producto->Nombre, 'categoria' => $categoria->nombre, 'tooltip' => $tooltip]; Yii::$app->response->format = 'json'; return $message; } }
<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>
/* @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