2014-03-25 89 views
0

在我的网站中,我有两个帐户,一个是管理员,一个是用户。管理员可以编辑,创建和删除。我实现的所有这些功能工作正常,但现在当我在另一个浏览器中打开我的用户,并在另一个浏览器中从管理员执行删除功能时,它不会自动更新到用户网站。我需要在我的用户网站中手动刷新我的页面以查看当前记录。Bootstrap删除数据库中的项目

当管理员进行修改时,自动更新/自动刷新用户页面的方法是什么?

下面是我在控制器中执行删除功能的代码。请让我知道我可以调整我的代码以自动刷新用户网站中的内容。

这是访问规则

public function accessRules() 
{ 
    return array(
     array('allow', // allow all users to perform 'index' and 'view' actions 
      'actions'=>array('index'), 
      'users'=>array('*'), 
     ), 
     array('allow', 
      'actions'=>array('view','user'), 
      'users'=>array('@'), 
     ), 
     array('allow', // allow admin user to perform 'admin' and 'delete' actions 
      'actions'=>array('create','update', 'admin','delete'), 
      'expression' => 'Yii::app()->user->isAdmin()' 
     ), 
     array('deny', // deny all users 
      'users'=>array('*'), 
     ), 
    ); 
} 

这是删除功能

public function actionDelete($id) 
{ 
    if(Yii::app()->request->isPostRequest) 
    { 
     // we only allow deletion via POST request 
     $this->loadModel($id)->delete(); 

     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser 
     if(!isset($_GET['ajax'])) 
      $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); 

    } 
    else 
     throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); 
} 
+0

请检查[这里] [1]后,建议对PHP的,只是申请成为MVC风格。 [1]:http://stackoverflow.com/questions/4629642/how-can-i-refresh-a-page-when-a-database-is-updated – StreetCoder

回答

0

我假设你熟悉JavaScript中使用AJAX。如果不是,请看看this.

1.现在,您可以在您的JavaScript中设置一个计时器,每10秒钟发出一个名为sat的计时器。在这个JavaScript代码中写入ajax调用。

var myVar=setInterval(function(){myTimer()},1000); 

function myTimer() 
{ 
//ajax call here 
} 

.2制作一个控制器,这个ajax函数会调用。说checkflag

public function actionCheckFlag() 
{ 
//check timestamp here, calculate timer difference between current time and the time of change in Db.You have to make timestamp with the each Db table. 
} 

,设定上采取行动的一些标准,可以说,当前的时间和db表的变化时间之间的差异说1分钟,然后返回一些标志。根据这个标志刷新更新一些特定的元素。让我们说更新gridView。或者你也可以重新加载整个页面就像

location.reload(); 
相关问题