如果在 yii 中取消它,如何在控制器中放置确认警报并重定向到特定的 link
how to put confirm alert in controller and redirect to perticular link if cancel it in yii
我想在控制器中放置确认警报,并在单击取消按钮时重定向到特定的 link。
我的 admin.php 代码是:
array(
'header' => 'Action',
'class' => 'CButtonColumn',
'template' => '{update}',
'updateButtonUrl' => 'Yii::app()->createUrl("attendance/inout", array("id"=>$data->supplier_master_id))'
)
这里我必须在控制器中放入确认警报,因为其中还放入了一些额外的条件。
我的控制器代码是:
public function actionInout($id) {
?>
<script>
if(confirm("Do you want to add record?")) {
// means proceed
} else {
// Should be redirect back to the grid view
}
</script>
<?php // further code
你不能用这种方式做到这一点。
控制器处理数据,但用户交互通过视图进行。
在这个意义上,正确的方法是在您的视图中实现相同的逻辑。按照这个逻辑,您将从控制器激活警报问题的出现。之后,根据您的回答,您将从控制器再次采取行动。我试图通过列出操作来说明这一点:
1. Controller makes initial tasks and calls view
2. User enters what needed and finish with view
3. Controller analyze input data and initialize alert event for view - again calls view. Of course in call controller keeps and sends to view already filled data.
4. View understood that it called with alert action and shows the alert
5. After user action the view sends all data ( already containing and answer ) to the controller.
6. Controller understands alert and goes where needed.
希望我已经理解了您的问题,并且我的回答能让您有所了解。
当然它可以是一个解决方案,其中所有 alert/answer 逻辑都由 javascript 进入视图,但它非常依赖于具体情况。
您可以在点击按钮时打开确认对话框,请将您的按钮代码更改为:
array(
'header' => 'Action',
'class' => 'CButtonColumn',
'template' => '{update}',
'buttons' => array(
'update' => array(
'url' => 'Yii::app()->createUrl("attendance/inout", array("id"=>$data->supplier_master_id))',
'click' => 'js:function(){if(!confirm("Do you want to add record?")) {return false;}}'
)
)
)
并从您的控制器中删除脚本
我自己找到了答案
因为我必须在控制器中放入确认警报,所以我在控制器中做了这样的操作:
public function actionInout($id,$final_status) { ?>
<script>
if(!confirm("Do you want to check- <?php echo $final_status; ?> to well sites.")) {
window.location.href = url; // back url
} else {
window.location.href = url1; // further process
}
</script>
<?php // code
我想在控制器中放置确认警报,并在单击取消按钮时重定向到特定的 link。 我的 admin.php 代码是:
array(
'header' => 'Action',
'class' => 'CButtonColumn',
'template' => '{update}',
'updateButtonUrl' => 'Yii::app()->createUrl("attendance/inout", array("id"=>$data->supplier_master_id))'
)
这里我必须在控制器中放入确认警报,因为其中还放入了一些额外的条件。
我的控制器代码是:
public function actionInout($id) {
?>
<script>
if(confirm("Do you want to add record?")) {
// means proceed
} else {
// Should be redirect back to the grid view
}
</script>
<?php // further code
你不能用这种方式做到这一点。 控制器处理数据,但用户交互通过视图进行。 在这个意义上,正确的方法是在您的视图中实现相同的逻辑。按照这个逻辑,您将从控制器激活警报问题的出现。之后,根据您的回答,您将从控制器再次采取行动。我试图通过列出操作来说明这一点:
1. Controller makes initial tasks and calls view
2. User enters what needed and finish with view
3. Controller analyze input data and initialize alert event for view - again calls view. Of course in call controller keeps and sends to view already filled data.
4. View understood that it called with alert action and shows the alert
5. After user action the view sends all data ( already containing and answer ) to the controller.
6. Controller understands alert and goes where needed.
希望我已经理解了您的问题,并且我的回答能让您有所了解。
当然它可以是一个解决方案,其中所有 alert/answer 逻辑都由 javascript 进入视图,但它非常依赖于具体情况。
您可以在点击按钮时打开确认对话框,请将您的按钮代码更改为:
array(
'header' => 'Action',
'class' => 'CButtonColumn',
'template' => '{update}',
'buttons' => array(
'update' => array(
'url' => 'Yii::app()->createUrl("attendance/inout", array("id"=>$data->supplier_master_id))',
'click' => 'js:function(){if(!confirm("Do you want to add record?")) {return false;}}'
)
)
)
并从您的控制器中删除脚本
我自己找到了答案
因为我必须在控制器中放入确认警报,所以我在控制器中做了这样的操作:
public function actionInout($id,$final_status) { ?>
<script>
if(!confirm("Do you want to check- <?php echo $final_status; ?> to well sites.")) {
window.location.href = url; // back url
} else {
window.location.href = url1; // further process
}
</script>
<?php // code