I have a form it is working ok, but in this form I have a field "qtd_clientes", this field is numerical, if i click on "create" the information are saved, but I need if the field "qtd_clientes" is greater than 1, fo exemplo the value of "qtd_clientes" is 3, must save the information 3 times on my database. How can I Do this?
I seen the example but I understand the idea. I should create function beforeAction, and this function call de actionCreate, until save the amount typed in field "qtd_clientes"? How can I Do this?
public function actionCreate()
{
for($i=1 ; $i<=2 ; $i++)
{
$model=new Cliente;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Cliente']))
{
$model->attributes=$_POST['Cliente'];
$model->save();
if($i == 2){$this->redirect(array('index'));}
}
$this->render('create',array(
'model'=>$model,
));
}
This code save the information 2 times on data base, but I put the value that finished loop direct on code $i<=2, I need get this value that be in "qtd_clientes" field of my _form.php. But I call the $model=new Cliente; inside the loop and I can not get the value before start loop. Whats I need change to do this?
I dont need tabular input, becouse I don’t want repeat The fields on the form, I need save the same information multiple times. The user typed the information on the form and the system save this information multiple times in database. For example if user typed value 3 in the field qtd_clientes, the system save the same infomation 3 times, if the user typed 4, the system save 4 times in the database.
public function afterSave()
{
parent::afterSave();
$model=Barang::model()->findByPK(kode_barang);
$model->jumlah_barang=$model->jumlah_barang+$this->jumlah_barang;
$model->save();
}