Hi Everyone
Im a real newbie in YII and to MVC. Im creating a basic form with 3 inputs, submit them and verify if the form is submitted at phase I . Im having ATM an error in the model, need a little support here. The ajax between marcas and models is working perfect btw.
Im getting the following error :
PHP Error
Undefined variable: model
"/home/alejandro/sites/yii/repuestos506/protected/views/site/index.php(17)"
"views/site/index.php"
<?php $this->pageTitle=Yii::app()->name; ?>
<?php echo Yii::app()->user->getFlash('busqueda'); ?>
Busqueda de Repuestos :
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'index-form',
'enableClientValidation'=>false,
'clientOptions'=>array(
'validateOnSubmit'=>false,
),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="flash-success">
</div>
<div class="row">
<?php $models = marca::model()->findAll();?>
<?php $list = CHtml::listdata($models,'id','marca'); ?>
<?php echo CHtml::dropDownList('marca', $models,
$list,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('cargaModelo'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#modelo', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)));
?>
</div>
<?php echo CHtml::dropDownList('modelo','', array('empty' => 'Modelos por marca')); ?>
<?php echo CHtml::TextField('repuesto') ?>
<div class="row buttons">
<?php echo CHtml::submitButton('Busqueda'); ?>
</div>
<?php $this->endWidget(); ?>
"controllers/SiteController.php"
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$model=new IndexForm;
if(isset($_POST['IndexForm']))
{
Yii::app()->user->setFlash('busqueda','Form Submitted');
} else {
Yii::app()->user->setFlash('busqueda','Not submitted');
}
$this->render('index');
}
"models/IndexForm.php"
<?php
class IndexForm extends CFormModel
{
public $marca;
public $modelo;
public $repuesto;
public function rules()
{
return array(
array('marca, modelo', 'required'),
);
}
}
?>
Thanks in advance for any help.