Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created April 17, 2013 14:04
Show Gist options
  • Save fprochazka/5404555 to your computer and use it in GitHub Desktop.
Save fprochazka/5404555 to your computer and use it in GitHub Desktop.
Hack for lazylinks to
<?php
use Nette\Application\UI;
class BasePresenter extends UI\Presenter
{
/**
* Returns destination as Link object.
* @param string destination in format "[[module:]presenter:]view" or "signal!"
* @param array|mixed
* @return Link
*/
public function lazyLink($destination, $args = array())
{
if (!is_array($args)) {
$args = func_get_args();
array_shift($args);
}
return new Redirect($this, $destination, $args);
}
}
<?php
$form->onSuccess[] = $presenter->lazyLink('Homepage:');
$form->onSuccess($form); // will trigger redirect
<?php
use Nette\Application\UI;
class Redirect extends UI\Link
{
/** @var UI\PresenterComponent */
private $component;
public function __construct(UI\PresenterComponent $component, $destination, array $params)
{
parent::__construct($component, $destination, $params);
$this->component = $component;
}
public function __invoke()
{
$this->component->redirect($this->getDestination(), $this->getParameters());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment