"Refreshes the current page. The effect of this method call is the same as user pressing the refresh button on the browser (without post data)"
So, I've written my code as below:
public function actionCancel($id=null)
{
$cad_oficio=$this->loadcad_oficio($id);
if ($cad_oficio->isCancelled()){
Yii::app()->user->setFlash('success',"Ofício is already cancelled!");
$this->refresh(true);
}
....
My intention is: Whetever the request comes, if my model is cancelled, I will refresh the original page with my flash information.
This works for my 'admin' page, but not for 'show' page. In the last, i get an 'invalid request' (probably an infinite loop).
How really refresh() works? Why it doesn't work for show? Is it refresh() able to do what I am wanting to do?
my show method:
public function actionShow()
{
if(isset($_POST['command'], $_POST['id']))
{
if ($_POST['command']==='cancel')
$this->actionCancel($_POST['id']);
//$this->refresh();
}
$this->render('show',array('cad_oficio'=>$this->loadcad_oficio()));
}
processAdminCommand() method:
protected function processAdminCommand()
{
if(isset($_POST['command'], $_POST['id']))
{
if ($_POST['command']==='delete')
$this->loadcad_oficio($_POST['id'])->delete();
if ($_POST['command']==='cancel')
$this->actionCancel($_POST['id']);
// reload the current page to avoid duplicated delete actions
$this->refresh();
}
}
you can create css style for success and fail (note the div tag)
public function actionShow()
{
if(isset($_POST['command'], $_POST['id']))
{
if ($_POST['command']==='cancel')
$this->actionCancel($_POST['id']);
Yii::app()->user->setFlash('success',"Ofício is already cancelled!");
}
$this->render('show',array('cad_oficio'=>$this->loadcad_oficio()));
}