rixxi / redirector
0.2.2
2014-06-18 19:51 UTC
Requires
- php: >=5.3.1
- nette/nette: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 16:34:34 UTC
README
解决事件中间的 $presenter->redirect([$code, ], $destination[, $arguments])
问题。
- 您只需要在监听器中包含redirector,无需包含应用或展示者。
- 所有附加的监听器都会被执行。假设它们不会杀死应用或抛出异常。
- 确保在整个系统中可能的第一次重定向点。
- 更简单的重定向测试。
假设您在整个系统中使用它。
配置
安装
composer install rixxi/redirector
配置
extensions: - Rixxi\Redirector\DI\RedirectorExtension
在展示者中启用支持
<?php use Rixxi\Application\UI\Presenter\EnableRedirector; class BasePresenter extends Nette\Application\UI\Presenter { use EnableRedirector; }
定义 BasePresenter::beforeRender 并请求注入redirector。
然后您可以自由地这样做
<?php class ExamplePresenter extends BasePresenter { /** @var \Service @ inject */ public $service; public function actionDefault() { $this->service->onError[] = function () { // redirect back on error $this->redirector->redirect('this'); // if you used $presenter->redirect here next events would not execute }; $this->service->onError[] = function () { // say something to admin $this->reporter->say('I might be sick!'); }; } }
现在想象一下围绕分布和(晚期)委托的想法的整个插件生态系统。