I've selected id from the button. Every time I select id to be copied to another page. Like a Cart Shoping, where you can see the selected products.
Here's what I've done
in Controller
public function actionClone($id)
{
$model = $this->findModel($id);
$newModel = new Masa();
$newModel->attributes = $model->attributes;
$newModel->save(false);
$newModel->save();
}
public function actionTabel()
{
$searchModel = new MasaSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
foreach( $model->models as $id) {
$newModel = new Masa();
$newModel->attributes = $id->attributes;
$newModel->save();
}
return $this->render('tabel',[
'models'=>$newModel,
]);
}
in view
'clone' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-floppy-open">Clonare</span>',
Yii::$app->urlManager->createUrl(['masa/clone', 'id' => $model->id]),
[
'title' => Yii::t('yii', 'Clonare'),
'url' => Url::to(["/masa/clone", 'id' => $model->id]),
]
) . "</li>";
},
I have two attributes id and name,for simplicity.
try to change method to GET , and now the data will be state in the url , and when you go back or return, the data not lose .
Html::a('<span class="glyphicon glyphicon-floppy-open">Clonare</span>',
Yii::$app->urlManager->createUrl(['masa/clone', 'id' => $model->id]),
[
'title' => Yii::t('yii', 'Clonare'),
'url' => Url::to(["/masa/clone", 'id' => $model->id]),
]
)
If you don't like to show ID you can encrypt
$decrypt = \Yii::$app->security->decryptByKey($_GET['id'], \Yii::$app->request->cookieValidationKey);
$encrypt=\Yii::$app->security->encryptByKey($id, \Yii::$app->request->cookieValidationKey);
If you want to show a new view, you must create one in the same route as the other "masa" views
New view masa/view.php
<div class="post-view">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Informaction of the Masa</h3>
</div>
<div class="box-body">
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'MassaId',
'value' => $model->id,
]
//....
]
])
?>
</div>
</div>
</div>
Controller
public function actionClone($id)
{
$model = $this->findModel($id);
$newModel = new Masa();
$newModel->attributes = $model->attributes;
$newModel->save(false);
$newModel->save();
return $this->render('view', [
'model' => $model,
]);
}