Nefunguju flashmessage pri redirect
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- srigi
- Nette Blogger | 558
Robim na modularnej app v PHP 5.3. Postupujem celkom dobre, ale teraz som
zistil, ze na backende (ale aj frontenede) mi nejdu flashmessage ak kdekolvek
(presenter, form callback) pouzijem $this->redirect()
. Ak dam
nastavenie flashmessage do akcie presentera, tak to funguje.
Celu app som v podstate vystaval na skeletone, prihlasovanie som spravil podla akrabat. V akrabate to beha krasne, v mojej app nie.
<?php
// glob. namespace
use Nette\Application\Presenter;
abstract class BasePresenter extends Presenter
{
public $oldLayoutMode = FALSE;
public $oldModuleMode = FALSE;
}
?>
<?php
namespace AdminModule;
use Nette\Environment;
class BasePresenter extends \BasePresenter
{
protected function beforeRender()
{
$user = Environment::getUser();
$this->template->user = ($user->isAuthenticated()) ? $user->getIdentity() : NULL;
}
}
?>
<?php
namespace AdminModule;
use Nette\Environment;
use Nette\Web\User;
class DashboardPresenter extends BasePresenter
{
protected function startup()
{
$user = Environment::getUser()->setAuthorizationHandler(new \Srigi_Acl());
if (!$user->isAuthenticated()) {
if ($user->getSignOutReason() === User::INACTIVITY) {
$this->flashMessage('You have been logged out due to inactivity. Please login again.');
}
$backlink = $this->getApplication()->storeRequest();
$this->redirect('Auth:login', array('backlink' => $backlink));
} else {
// only ADMIN or ROOT can access Presenter
if (!$user->isAllowed($this->reflection->name, $this->getAction())) {
$this->flashmessage('Na vstup do admin sekcie nemáte dostatočné oprávnenia!'); // nejde
$this->redirect('Auth:login');
}
}
parent::startup();
}
public function actionDefault()
{
}
public function actionLogout()
{
Environment::getUser()->signOut();
$this->flashMessage('You have been logged off.'); // nejde
$this->redirect('Auth:login');
}
}
?>
<?php
namespace AdminModule;
use Nette\Environment;
use Nette\Forms\Form;
use Nette\Application\AppForm;
use Nette\Security\AuthenticationException;
class AuthPresenter extends BasePresenter
{
/** @persistent */
public $backlink = '';
protected function createComponentLoginForm($name)
{
$form = new AppForm($this, $name);
$form->addText('login', 'Email:')
->addRule(Form::EMAIL, 'Prosím zadajte registračný email.');
$form->addPassword('password', 'Password:')
->addRule(Form::FILLED, 'Prosím zadajte heslo.');
$form->addSubmit('send', 'Log in!');
$form->onSubmit[] = array($this, 'loginFormSubmitted');
$form->addProtection('Prosím odošlite prihlasovacie údaje znova (vypršala platnosť tzv. bezpečnostného tokenu).');
}
public function loginFormSubmitted($form)
{
try {
$user = Environment::getUser();
$user->authenticate($form['login']->value, $form['password']->value);
$this->getApplication()->restoreRequest($this->backlink);
$this->flashmessage('fsdfsdfsdf', 'jj'); // nejde
$this->redirect('Dashboard:default');
} catch (AuthenticationException $e) {
$form->addError($e->getMessage());
}
}
}
?>
Poradte pls, kde by som mal debugovat (Xdebug mi ako tak ide). Napr. pri
logoute mam v URL identifikator _fid
, ale message nikde. Este sem
dam kus layout, ale ten mam tiez zo skeletonu:
<div id="content">
{foreach $flashes as $flash}<div class="flash {$flash->type}">{$flash->message}</div>{/foreach}
{include #content}
</div><!-- #content -->