How can i create a database of random generated numbers?? I tried to do that using the CRUD generated by gii, modifying the actionCreate. But when i store the numbers, only the last generated number gets stored in the model database?? I used a for loop to generate the multiple random numbers, but only the last generated number gets stored in the database using this->save(false). Can anyone offer a clue?
I think you forgot to reset your model after saving, so Yii does update instead of insert.
Orey, please how do i reset the model?? Thanks for your insight.
I meant you possibly have something like this:
$model = new MyModel;
$model->value = $random;
$model->save(); // insert
$model->value = $random;
$model->save(); // update
$model->value = $random;
$model->save(); // update
but you need to create new model every time.
(AFAIR there’s another way, like setting id to null, but start with above).
Which is right?
$model = new MyModel;
for($i=0; $i<10; $i++){
$model->value = $random;
$model->save(); // insert
$model->id = NULL;
}
or
for($i=0; $i<10; $i++){
$model = new MyModel;
$model->value = $random;
$model->save(); // insert
}
thanks.
second.
Thanks, the second did work!!