gpt4 book ai didi

yii2 - 如何在 yii2 中更改操作列上的 View 、更新和删除 url

转载 作者:行者123 更新时间:2023-12-03 22:47:50 24 4
gpt4 key购买 nike

我在 Controller 中创建了更新和 View 操作,但此操作在索引页中的操作列上没有更改

 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,
]);
}
}

最佳答案

       [
'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;
}

}
],

关于yii2 - 如何在 yii2 中更改操作列上的 View 、更新和删除 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38692362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com