/** * Redirect to a specific page. * * @param string $target Page to redirect to. * @param array $data Optional data to save in a users session. */ protected function redirect($target, $data = null) { // Write optional session data if ($data instanceof Messages) { Session::flash('errors', $data->toArray()); } else { if (is_array($data)) { Session::flash($data); } else { if (!is_null($data)) { Session::flash('data', $data); } } } // Allow to specify the redirect uri as parameter $url = r::get('redirect_to'); if (!empty($url)) { redirect::to($url); } // Perform redirect switch ($target) { case 'home': redirect::home(); break; case 'back': redirect::back(); break; case '404': $page = site()->errorPage(); redirect::to($page->uri()); break; case 'referer': $referer = server::get('HTTP_REFERER'); redirect::to($referer); break; default: redirect::to($target); break; } }
/** * Plugin Filters * * Allows to register filters that can be used to run application logic just * before a route action is executed. * * @see CommentPlugin::routes() * @var array */ return array('auth' => function () { if (!user::current() || !user::current()->isAdmin()) { redirect::to('plugin/comments/wizard'); } }, 'installed' => function () { if ($this->isInstalled()) { redirect::home(); } }, 'userCanCreate' => function () { $route = plugin('comments')->route(); $hash = a::first($route->arguments()); $page = site()->index()->findBy('hash', $hash); return $page instanceof Page && $page->isVisible(); }, 'userCanRead' => function () { $route = plugin('comments')->route(); $hash = a::first($route->arguments()); $page = site()->index()->findBy('hash', $hash); return $page instanceof Page && $page->isVisible(); }, 'userCanUpdate' => function () { $route = plugin('comments')->route(); $id = a::last($route->arguments()); $comment = comment::find($id);