Created
April 17, 2013 14:04
-
-
Save fprochazka/5404555 to your computer and use it in GitHub Desktop.
Hack for lazylinks to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$form->onSuccess[] = $presenter->lazyLink('Homepage:'); | |
$form->onSuccess($form); // will trigger redirect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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