[英]Yii2 - Pass table field to view from other controller
我有這個DetailView,它在屬於ProdutosController
的視圖中渲染了一些字段(foto,nome等)。 在detailView內部是一個超鏈接,該超鏈接將為顯示的每個記錄顯示,並在按下時呈現EncomendasController
的視圖,並且EncomendasController
必須僅顯示激活了“ Comprar”超鏈接的產品的名稱(字段名稱) 。
<?= DetailView::widget([
'model' => $model,
'options' => ['class' => 'detail1-galeria-view2'],
'attributes' => [
// cria um array com a fotografia, em que carrega a path no campo fieldName da bd
[
'attribute'=>'',
//'value'=>$model->foto,
'value'=>Html::a(Html::img(Yii::$app->getUrlManager()->getBaseUrl() . "/" .$model->foto, ['width'=>'192', 'height' => "256"]), $model->foto),
'format' => 'raw',
],
[
'attribute'=>'',
'value'=>$model->nome,
],
[
'attribute'=>'',
'value'=>$model->categoria,
],
[
'attribute'=>'',
'value'=>$model->descricao,
],
[
'attribute'=>'',
'value'=>$model->valor.' '.'€',
],
// info
[
'attribute'=>'',
'format' => 'raw',
'value'=> Html::a(Yii::t('app','Comprar'), Url::toRoute(['encomendas/create'])),
],
],
]) ?>
我如何只將產品的detailView字段“ nome”傳遞給我,在其中我按了超鏈接按鈕到另一個名為EncomendasController
控制器的另一個視圖,然后在新視圖中顯示相同的名稱?
您可以傳遞controller name
然后傳遞controller method
作為URL
並傳遞'nome'
作為屬性。 此'nome'
將被redirected
到頁面。
視圖
'value'=> Html::a(Yii::t('app','Comprar'), Url::toRoute(['encomendas/create', 'nome' => $model->nome])),
控制者
class EncomendasController
{
.
.
public function actionCreate($nome) {
$nome = Yii::$app->request->get('nome');
return $this->redirect('create',['nome'=>$nome]);
}
.
.
}
create.php (查看)
<?php echo $nome;?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.