我已从按钮中选择了ID。每次我选择要复制到另一个页面的ID。就像购物车一样,您可以在其中看到所选产品。
这就是我所做的
控制器中的
<ul id="payment_form_quickpaypayment_payment">
<li>
<table>
<tbody>
<tr>
<td>
<input type="radio" class="radio" name="qpayment_type" value="dankort" checked="checked">
</td>
<td>
<img src="/dankort.png" title="Dankort">
</td>
</tr>
<tr>
<td>
<input type="radio" class="radio" name="qpayment_type" value="mastercard">
</td>
<td>
<img src="/mastercard.png" title="MasterCard">
</td>
</tr>
<tr>
<td>
<input type="radio" class="radio" name="qpayment_type" value="mastercard-debet">
</td>
<td>
<img src="/mastercarddebet.png" title="MasterCard Debet DK">
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<script>
function payLoad() {
var selectedImage = document.getElementById("payment_form_quickpaypayment_payment").getElementsByTagName('img');
var i;
for (i = 0; i < selectedImage.length; i++) {
var newSpan = document.createElement("span");
newSpan.innerText = selectedImage[i].title
selectedImage[i].parentNode.appendChild(newSpan);
}
}
window.onload = payLoad;
</script>
在视图中
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,
]);
}
为简单起见,我有两个属性id和name。
答案 0 :(得分:0)
尝试将方法更改为GET,现在数据将在url中显示,当您返回或返回时,数据不会丢失。
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]),
]
)
如果您不想显示身份证,可以加密
$decrypt = \Yii::$app->security->decryptByKey($_GET['id'], \Yii::$app->request->cookieValidationKey);
$encrypt=\Yii::$app->security->encryptByKey($id, \Yii::$app->request->cookieValidationKey);
如果要显示新视图,则必须在与另一个视图相同的路径中创建一个视图&#34; masa&#34;视图
新视图 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>
控制器
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,
]);
}