Skip to content

Commit 949164f

Browse files
committed
PresenterComponent: added redirectPermanent()
1 parent 9869e52 commit 949164f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Application/UI/PresenterComponent.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ public function redirect($code, $destination = NULL, $args = [])
355355
}
356356

357357

358+
/**
359+
* Permanently redirects to presenter, action or signal.
360+
* @param string destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
361+
* @param array|mixed
362+
* @return void
363+
* @throws Nette\Application\AbortException
364+
*/
365+
public function redirectPermanent($destination = NULL, $args = [])
366+
{
367+
$args = func_num_args() < 3 && is_array($args) ? $args : array_slice(func_get_args(), 1);
368+
$presenter = $this->getPresenter();
369+
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'), 301);
370+
}
371+
372+
358373
/********************* interface \ArrayAccess ****************d*g**/
359374

360375

tests/UI/PresenterComponent.redirect().phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,19 @@ test(function () use ($presenter) {
7676
Assert::same(301, $presenter->response->getCode());
7777
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
7878
});
79+
80+
81+
test(function () use ($presenter) {
82+
$presenter->redirectPermanent('foo', 2);
83+
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
84+
Assert::same(301, $presenter->response->getCode());
85+
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());
86+
});
87+
88+
89+
test(function () use ($presenter) {
90+
$presenter->redirectPermanent('foo', ['arg' => 1]);
91+
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
92+
Assert::same(301, $presenter->response->getCode());
93+
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());
94+
});

0 commit comments

Comments
 (0)