我已在控制器中对更新和视图创建操作,但此操作在索引页中的操作列上不会更改
public function actionLeadView($id){
$id = $_GET['id'];
$model = Leads::findOne($id);
return $this->render('viewlead', [
'model' => $model,
]);
}
public function actionLeadUpdate($id){
$id = $_GET['id'];
$model = Leads::findOne($id);
date_default_timezone_set("Asia/Kolkata");
$date = date('Y/m/d H-i-sa');
if ($model->load(Yii::$app->request->post())) {
$model->modified = $date;
if($model->validate()){
$model->save();
return $this->redirect(['viewlead', 'id' => $model->id]);
}else {
return $this->render('updatelead', [
'model' => $model,
]);
}
}
else
{
return $this->render('updatelead', [
'model' => $model,
]);
}
}
答案 0 :(得分:28)
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Actions',
'headerOptions' => ['style' => 'color:#337ab7'],
'template' => '{view}{update}{delete}',
'buttons' => [
'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'lead-view'),
]);
},
'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'lead-update'),
]);
},
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('app', 'lead-delete'),
]);
}
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
$url ='index.php?r=client-login/lead-view&id='.$model->id;
return $url;
}
if ($action === 'update') {
$url ='index.php?r=client-login/lead-update&id='.$model->id;
return $url;
}
if ($action === 'delete') {
$url ='index.php?r=client-login/lead-delete&id='.$model->id;
return $url;
}
}
],
答案 1 :(得分:6)
因为问题是
如何更改yii2中操作列的视图,更新和删除网址
我通过添加删除操作
来改善@ insane-skull的答案[
'class' => 'yii\grid\ActionColumn',
'template' => '{leadView} {leadUpdate} {leadDelete}',
'buttons' => [
'leadView' => function ($url, $model) {
$url = Url::to(['controller/lead-view', 'id' => $model->whatever_id]);
return Html::a('<span class="fa fa-eye"></span>', $url, ['title' => 'view']);
},
'leadUpdate' => function ($url, $model) {
$url = Url::to(['controller/lead-update', 'id' => $model->whatever_id]);
return Html::a('<span class="fa fa-pencil"></span>', $url, ['title' => 'update']);
},
'leadDelete' => function ($url, $model) {
$url = Url::to(['controller/lead-delete', 'id' => $model->whatever_id]);
return Html::a('<span class="fa fa-trash"></span>', $url, [
'title' => 'delete',
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
]);
},
]
答案 2 :(得分:6)
通常您需要在操作按钮的URL中更改控制器名称。您可以使用 urlCreator
轻松完成[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return Url::to(['another-controller-name/'.$action, 'id' => $model->id]);
}
],
答案 3 :(得分:5)
在gridview中,
<!--fabric js -->
console.log("Matrix :"+polygon.calcTransformMatrix());
答案 4 :(得分:1)
我是Yii2
的新用户,感谢您帮助我使用您的代码@cbaconnier。
这是您的代码,稍作修改:
[
'class' => 'yii\grid\ActionColumn',
'template' => '{leadView} {leadUpdate} {leadDelete}',
'buttons' => [
'leadView' => function ($url, $model) {
$url = Url::to(['datakegiatan/view', 'id' => $model->ID_DATA]);
return Html::a('<span class="fa fa-eye"></span>', $url, ['title' => 'view']);
},
'leadUpdate' => function ($url, $model) {
$url = Url::to(['datakegiatan/update', 'id' => $model->ID_DATA]);
return Html::a('<span class="fa fa-pencil"></span>', $url, ['title' => 'update']);
},
'leadDelete' => function ($url, $model) {
$url = Url::to(['datakegiatan/delete', 'id' => $model->ID_DATA]);
return Html::a('<span class="fa fa-trash"></span>', $url, [
'title' => 'delete',
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
]);
},
]],
答案 5 :(得分:0)
如果只想更改网址并保留默认按钮,请使用属性urlCreator
。
'class' => 'yii\grid\ActionColumn',
'template' => '{delete} ',
'urlCreator' => function ($action, $model, $key, $index) {
return Url:to(["controller/action"]);
}