I want to enter data in database from one table to another table with the help of a button.
How to do it Please suggest.
I want to enter data in database from one table to another table with the help of a button.
How to do it Please suggest.
Using form?
view.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'myform',
'enableClientValidation'=>false,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<?= CHtml::submitButton('Trnasfer data', array('id => 'mysubmit')); ?>
<?php $this->endWidget(); ?>
[b]
Controller.php[/b]
if(isset($_POST['mysubmit']))
{
$posts = Post::model()->findAll();
foreach ($posts as $post) {
$post2 = new Post2;
$post2->attribute = $post->attribute;
$post2->save();
}
}