如何使用 Yii 1.4.x 中的 CJuiDialog 框内容修复此会话?
how to fix this session with my CJuiDialog box content in Yii 1.4.x?
我正在处理的部分是由 Yii 1 提供支持的 Web 应用程序的模块之一。4.x。我的索引视图文件中有一个 CGridView。然后在里面,我有自定义按钮。其中一个按钮是弹出一个对话框。这是我提到的那个自定义按钮的片段
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->controller->createUrl("myControllerName/view",array("id" => "$data->id"))',
'options' => array(
'ajax' => array(
'type' => 'POST',
'url' => "js:$(this).attr('href')",
'dataType' => "json",
'async' => false,
'success' => 'function(data){
$("#detail-dialog").dialog("open"); return false;
}',
'update' => '#detail'
)
)
),
这是控制器中名为 'view' 的控制器操作的片段
public function actionView(){
$gid = $_GET['id'];
$data = array();
if(Yii::app()->request->isAjaxRequest) {
$model = MyModelName::model()->findById($gid);
if (!empty($model) || !is_null($model)) {
$attributes = $model->getAttributes();
$result = MyModelName::model()->findByKey($attributes['key'], $attributes['new_key']);
if(!empty($result)){
foreach($result as $key => $val){
$data['model'][$key] = $val;
}
$data['code'] = self::CODE_AJAX_SUCCESS;
}
} else {
$data['code'] = self::CODE_AJAX_ERROR;
}
$_SESSION['ajaxresponse'] = json_encode($data);
echo json_encode($data);
exit;
}
在我的视图文件的 CGridView 底部,我有 CJuiDialog 的这个片段
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'detail-dialog',
'options' => array(
'title' => 'Edit Data',
'autoOpen' => false,
'modal' => false,
'width' => 600,
'height' => 500,
'close' => 'js:function(){
//nothing here
}'
),
)); ?>
$result = $_SESSION['ajaxresponse'];
$this->renderPartial('_view',array('viewajaxresponse' => $result));
$this->endWidget('zii.widgets.jui.CJuiDialog');
每当我单击 CGridView 中的一行时,它会弹出 CJuiDialog 框,以及其中的 ajax 响应
因为我从会话中渲染了它的一部分。
现在的问题是,假设我关闭了 CJuiDialog 框,然后单击了 CGridView 中的第二行或另一行,对话框的内容仍然保留在我单击的第一行中,除非我强制刷新浏览器好像有两三遍,对话框里面的数据就变了。如何解决这个问题?
我什至实现了 CJuiDialog 框 'close' 事件的 ajax 函数以终止会话
$.ajax({
url: "'.Yii::app()->controller->createUrl("MyControllerName/destroysession", array("s"=>"ajaxresponse")).'",
type: "POST",
dataType: "json",
async: true,
success: function(data){
document.location.reload(true);
}
});
然后在控制器动作中
public function actionDestroysession(){
$name = !empty($_GET['s'])?$_GET['s']:'';
if(isset($name)){
unset($_SESSION[$name]);
$data['code'] = self::CODE_AJAX_SUCCESS;
echo json_encode($data);
exit;
}
echo $data['code'] = self::CODE_AJAX_ERROR;
exit;
}
这次的问题是,它完全终止了会话,即使您在函数中看到,我只终止了一个特定的会话变量,因为我传递了名称,但是当我单击 CGridView 中的任何行时, CJuiDialog 框旁边没有数据显示.. 那么如何解决这个会话问题呢?
解决这个问题的方法是,在 CjuiDialog 框内创建 CJuiTabs 时永远不要使用会话。最好从控制器生成 Cjuitab,然后将其用作 ajax 对触发 CjuiDialog 框的视图文件的响应
我正在处理的部分是由 Yii 1 提供支持的 Web 应用程序的模块之一。4.x。我的索引视图文件中有一个 CGridView。然后在里面,我有自定义按钮。其中一个按钮是弹出一个对话框。这是我提到的那个自定义按钮的片段
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->controller->createUrl("myControllerName/view",array("id" => "$data->id"))',
'options' => array(
'ajax' => array(
'type' => 'POST',
'url' => "js:$(this).attr('href')",
'dataType' => "json",
'async' => false,
'success' => 'function(data){
$("#detail-dialog").dialog("open"); return false;
}',
'update' => '#detail'
)
)
),
这是控制器中名为 'view' 的控制器操作的片段
public function actionView(){
$gid = $_GET['id'];
$data = array();
if(Yii::app()->request->isAjaxRequest) {
$model = MyModelName::model()->findById($gid);
if (!empty($model) || !is_null($model)) {
$attributes = $model->getAttributes();
$result = MyModelName::model()->findByKey($attributes['key'], $attributes['new_key']);
if(!empty($result)){
foreach($result as $key => $val){
$data['model'][$key] = $val;
}
$data['code'] = self::CODE_AJAX_SUCCESS;
}
} else {
$data['code'] = self::CODE_AJAX_ERROR;
}
$_SESSION['ajaxresponse'] = json_encode($data);
echo json_encode($data);
exit;
}
在我的视图文件的 CGridView 底部,我有 CJuiDialog 的这个片段
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'detail-dialog',
'options' => array(
'title' => 'Edit Data',
'autoOpen' => false,
'modal' => false,
'width' => 600,
'height' => 500,
'close' => 'js:function(){
//nothing here
}'
),
)); ?>
$result = $_SESSION['ajaxresponse'];
$this->renderPartial('_view',array('viewajaxresponse' => $result));
$this->endWidget('zii.widgets.jui.CJuiDialog');
每当我单击 CGridView 中的一行时,它会弹出 CJuiDialog 框,以及其中的 ajax 响应 因为我从会话中渲染了它的一部分。
现在的问题是,假设我关闭了 CJuiDialog 框,然后单击了 CGridView 中的第二行或另一行,对话框的内容仍然保留在我单击的第一行中,除非我强制刷新浏览器好像有两三遍,对话框里面的数据就变了。如何解决这个问题?
我什至实现了 CJuiDialog 框 'close' 事件的 ajax 函数以终止会话
$.ajax({
url: "'.Yii::app()->controller->createUrl("MyControllerName/destroysession", array("s"=>"ajaxresponse")).'",
type: "POST",
dataType: "json",
async: true,
success: function(data){
document.location.reload(true);
}
});
然后在控制器动作中
public function actionDestroysession(){
$name = !empty($_GET['s'])?$_GET['s']:'';
if(isset($name)){
unset($_SESSION[$name]);
$data['code'] = self::CODE_AJAX_SUCCESS;
echo json_encode($data);
exit;
}
echo $data['code'] = self::CODE_AJAX_ERROR;
exit;
}
这次的问题是,它完全终止了会话,即使您在函数中看到,我只终止了一个特定的会话变量,因为我传递了名称,但是当我单击 CGridView 中的任何行时, CJuiDialog 框旁边没有数据显示.. 那么如何解决这个会话问题呢?
解决这个问题的方法是,在 CjuiDialog 框内创建 CJuiTabs 时永远不要使用会话。最好从控制器生成 Cjuitab,然后将其用作 ajax 对触发 CjuiDialog 框的视图文件的响应