aqui va el controlador:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['index','create','update','delete','view'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Facturas models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new FacturasSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Facturas model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Facturas model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Facturas();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Facturas model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Facturas model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Facturas model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Facturas the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Facturas::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
VISTA;
<div class="facturas-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'Fecha')->widget (\yii\jui\DatePicker::classname(), [
'dateFormat' => 'dd-MM-yyyy',
'value' => date('d/m/y'),
'options' => ['style' => 'position: relative; z-index:999', 'class' => 'form-control','placeholder'=>'Haga click para seleccionar fecha']
])
?>
<?php
echo $form->field($model, 'Hora')->widget(kartik\time\TimePicker::classname(),[
'pluginOptions' => [
'showSeconds' => true,
'showMeridian' => false,
'minuteStep' => 1,
//'secondStep' => 5,
]
])
?>
<?php
$perfumes = ArrayHelper::map(Perfumes::find()->where(['Stock' =>1])->orderBy('NombrePerfume')->all(),'NombrePerfume','NombrePerfume','Tamanio');
echo $form->field($model,'Producto')->widget(Select2::classname(), [
'data' =>$perfumes,
'language' => 'es',
'options' => ['placeholder' => 'Seleccione un perfume...'],
'pluginOptions' => ['allowClear' =>true],
]);
?>
<?= $form->field($model, ‘Cantidad’)->textInput([‘placeholder’=>‘Ingrese una cantidad (SOLO NUMERICO)…’]) ?>
<?php
echo $form->field($model, 'Total')->widget(MaskMoney::classname(),
[
'pluginOptions' => [
'prefix' => '$ ',
'allowNegative' => false
]
]);
?>
<?php
$clientes = ArrayHelper::map(Clientes::find()->where(['status' =>1])->orderBy('NombreCliente')->all(),'idCliente','NombreCliente');
echo $form->field($model,'idCliente')->widget(Select2::classname(), [
'data' =>$clientes,
'language' => 'es',
'options' => ['placeholder' => 'Seleccione un cliente...'],
'pluginOptions' => ['allowClear' =>true],
]);
?>
<?= $form->field($model, 'Comentario')->textArea(['placeholder'=>'Escriba un comentario...','maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>