我正在开发一个网站,首次访问时,系统会要求用户输入电子邮件以及他/她所居住的城市。我使用colorbox和iframe加载它。这是main.php中的代码:
Yii::app()->clientScript->registerScript('',
"$('document').ready(
function()
{
$.fn.colorbox({href:'http://www.veevou.com/visitor/create',
iframe:true,'width':'365px', 'height':'510px', onClosed:function(){ location.reload(true); }});
}
)");
$colorbox = $this->widget('application.extensions.colorpowered.ColorBox');
$colorbox
->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'80%'));
因此,您看,colorbox将呈现页面create.php,在提交表单后,控制器将保存数据,然后重定向到索引页面。
这是控制器:
if(isset($_POST['Visitor']))
{
$model->attributes=$_POST['Visitor'];
// Register only if he / she is not registered as member nor visitor
if($model->save())
{
echo "<script>parent.$.fn.colorbox.close(); </script>";
$this->redirect(array('site/index'));
}
}
else
{
$this->render('form',compact('model'));
}
但它说“无法修改已发送的标头......”。如何关闭彩盒?我曾尝试将“父。$。fn.colorbox.close();”重定向到另一个页面,但它没有用。我应该把$ .fn.colorbox.close()放在哪里?我在另一篇文章中尝试了几种方法,但没有一种适合我。感谢
答案 0 :(得分:0)
你的问题就在这一部分。
echo "<script>parent.$.fn.colorbox.close(); </script>";
$this->redirect(array('site/index'));
您在屏幕上回显某些内容然后重定向,这是不可能的。你想要做的是重定向而不回应任何东西。之后,您需要确保颜色框不会再次打开。