使用Kohana制作用户个人资料

Joe*_*ssi 2 php kohana kohana-3 kohana-auth

我正在运行Kohana 3,并且很难理解Auth模块,或者即使它是我需要的.基本上我想创建一个基本的用户配置文件站点,具有基本的用户名/密码保护.

如何使用现有的控制器......

class Controller_Profile extends Controller
{
    function action_index( $user_id )
    {
        // User should already be authenticated by here I think
    }
}
Run Code Online (Sandbox Code Playgroud)

...并将它们与某种身份验证系统一起使用

The*_*per 6

对于Kohana 3,您需要办理入住手续,before而不是__construct像JIStone建议的那样.

public function before()
{
    parent::before();

    // This automatically checks for an auto login cookie (thanks kemo).
    if ( ! Auth::instance()->logged_in())
    {
        // Redirect to a login page (or somewhere else).
        $this->request->redirect('');
    }
}
Run Code Online (Sandbox Code Playgroud)

简单到足以理解.您可以将其放入控制器并让所有需要身份验证的控制器进行扩展.