我有这个扩展 Controller_Template 的类。
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Controller_Common extends Controller_Template {
public $template = 'main';
public function before()
{
parent::before();
View::set_global('title', 'Мій сайт');
View::set_global('description', 'Сайт');
$this->template->content = '';
$this->template->styles = array('style');
$this->template->scripts = '';
}
} // End Common
在控制器类中,我想重定向到另一个动作。
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_User extends Controller_Common {
public function action_info()
{
$this->template->content = View::factory('user/info')
->bind('user', $user);
// Load the user information
$user = Auth::instance()->get_user();
// if a user is not logged in, redirect to login page
if (!$user)
{
Request::current()->redirect('user/login');
}
}
public function action_login()
{
try{
if (HTTP_Request::POST == $this->request->method())
{
// Attempt to login user
$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
$username = $this->request->post('username');
$password = $this->request->post('password');
$user = Auth::instance()->login($username, $password, true);
$logged = Auth::instance()->logged_in('login');
// If successful, redirect user
if($user)
{
$this->redirect("user/info");
}
else
{
$message = 'Login failed';
}
}
/**/
}catch(Exception $e)
{
var_dump($e->getMessage());
}
$this->template->content = View::factory('user/login')
->bind('message', $message);
}
public function action_logout()
{
/*// Log user out
Auth::instance()->logout();
// Redirect to login page
Request::current()->redirect('user/login');*/
}
}
?>
我在 action_login 中使用此代码
$this->redirect("user/info");
但是重定向不起作用。如何解决这个问题?我用的是 Kohana 3.3.0 版本