开发者

CakePhp - render a view + afterFilter

The problem is i want to call the index function, i need it to render the view and then the afterFilter to redirect again to the index function and do the same.. Like a loop, the problem is it doesnt render it, ive tried using $this->render('index') but it doesnt work and also other things..

PS: I didnt include all the code that i have in index, because its pointless, doesnt render with or without it, just included the things i needed for the view.

function afterFilter()
{

if ($this->params['action'] == 'index')
{
   sleep(3);
   $this->redirect(array('action'=>'index',$id), null, true);
}

}

THE FUNCTION

function index($ido = 0)
{

$this->set('Operator', $this->Operator->read(null, $ido));
$this->set('ido', $ido);
}

THE VIEW = INDEX.CTP

  <legend>Operator StandBy Window</legend>
  <?php



  ?>

 </fieldset>

   <?php echo $html->link('LogIn', array('controller' => 'operators', 'action' => 'add'));  ?>
   <?php echo $html->link('LogOut', array('controller' => 'operators', 'action开发者_运维百科' => 'logout',$ido));  ?>


a function that constantly checks my database for a change, if a change occurs ill redirect, if not i need to have that constant loop of 'checking the database' and 'rendering the view'.

This is not possible entirely on the server with PHP, and especially not with CakePHP's template system. PHP just "makes pages" on the server and sends them to the browser and a linear fashion. If you loop on the server, the content of your page will just repeat itself:

Normal content
Normal content
Normal content
<redirect>

To redirect the client, you need to output headers. The headers need to be output before anything else. If you've already looped a few times and content has already been sent to the client, you can't redirect anymore.

There are two ways:

  • You just output one page at a time showing the current status, with a meta tag that'll refresh the page every x seconds. This can be rather expensive and annoying though.
  • Use AJAX and possibly Comet to update the information on the page dynamically in the browser.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜