Globáílní filtr a flashMessage po redirectu
- davidpustai
- Člen | 3
Ahoj,
mám router a používám globální filtr (načítám slug z DB). Vše
funguje, dokud nepotřebuji zavolat redirect
po
flashMessage
. _fid
se nepřenese a zpráva
nevyskočí.
$this->flashMessage("Zpráva.");
$this->redirect("Article:show", $id);
Zjedodušený Router:
public function createRouter()
{
$router = new RouteList;
$router[] = new Route('<article_slug .+>', [
null => [
Route::FILTER_IN => function($params) { return $this->getArticleBySlug($params); },
Route::FILTER_OUT => function($params) { return $this->getSlugByArticle($params); }
]
]);
return $router;
}
private function getArticleBySlug($params)
{
$article = $this->entityManager->getRepository(Article::class)->findOneBy(["slug" => $params["article_slug"]]);
if ($article !== null) {
return [
"presenter" => "Article",
"action" => "show",
"id" => $article->getId()
];
}
return null;
}
private function getSlugByArticle($params)
{
if ($params["action"] == "show") {
$article = $this->entityManager->find(Article::class, $params["id"]);
if ($article !== null) {
return [
"article_slug" => $article->getSlug()
];
}
}
return null;
}
- MajklNajt
- Člen | 498
asi by som skúsil správanie Route::FILTER_OUT
upraviť
takto:
private function getSlugByArticle($params)
{
if ($params["action"] == "show") {
$article = $this->entityManager->find(Article::class, $params["id"]);
if ($article !== null) {
$params["article_slug"] = $article->getSlug();
}
}
return $params;
}
- davidpustai
- Člen | 3
MajklNajt napsal(a):
asi by som skúsil správanie
Route::FILTER_OUT
upraviť takto:private function getSlugByArticle($params) { if ($params["action"] == "show") { $article = $this->entityManager->find(Article::class, $params["id"]); if ($article !== null) { $params["article_slug"] = $article->getSlug(); } } return $params; }
Beze změny. :/