<?php
class HomepagePresenter extends BasePresenter
{
public function renderDefault()
{
$this->template->time = date(DATE_RFC822);
}
public function handleRefresh()
{
if( $this->isAjax() ) {
$this['com']->invalidateControl();
} else {
$this->redirect('this');
}
}
public function handleRefreshDelay()
{
if( $this->isAjax() ) {
sleep(4);
$this['com']->invalidateControl();
} else {
$this->redirect('this');
}
}
protected function createComponentCom()
{
return new Com();
}
}
<?php
/**
* Componenta Com
*/
class Com extends Nette\Application\UI\Control
{
public function render()
{
$this->template->setFile(__DIR__ . '/Com.latte');
$this->template->time = date(DATE_RFC822);
$this->template->render();
}
public function handleRefresh()
{
if( $this->parent->isAjax() ) {
$this->invalidateControl('com');
} else {
// redirect může jen presenter, nikoliv komponenta
$this->parent->redirect('this');
}
}
}