小编ant*_*ony的帖子

Kohana Auth模块无法登录

对于那些熟悉Kohana中的Auth模块的人,我无法登录用户.我可以创建一个用户很好,但显然哈希不匹配.我已经使用提供MySql架构来创建数据库,而我正在使用模块模型.

这是我创建用户代码:

    public function user_create()
    {
        $user = ORM::factory('user');
        $user->username = "user";

        $this->auth = Auth::instance();

        $user->email = "info@test.com";
        $user->password = $this->auth->hash_password('admin');
        $user->add(ORM::factory('role', 'login'));
        $user->add(ORM::factory('role', 'admin'));

        if ($user->save())
            {
                $this->template->title = "user saved";
                $this->template->content = "user saved";
            }
        }
Run Code Online (Sandbox Code Playgroud)

它创建一个具有散列密码的用户,并为其提供正确的登录/管理员角色.数据库中的一切看起来都很好.这是我的登录代码.我跳过了检查用户是否已登录的开头部分.

            $user = $this->input->post('username');
        $password = $this->input->post('password');

        if(!empty($user))
            {
                $find_user = ORM::factory('user')->where('username', $user)->find();
                $username = $find_user->username;

                $this->auth = Auth::instance();

                if($this->auth->login($username, $password))
                    {
                        $error = "logged in";
                    }
                else
                    {
                        $error = "not logged in at all";
                    }
            }

        $this->template->content = new View('admin/login_view'); …
Run Code Online (Sandbox Code Playgroud)

php kohana

3
推荐指数
1
解决办法
2616
查看次数

需要在PHP中调用父类中的方法

正如标题所述,我正在尝试在父类中创建一个方法.虽然,我想它可以是任何一个班级.例如:

class Parent
   {
      function foo ()
        {
           // do stuff
        }
   }

  class Child extends Parent
    {
       function bar ()
        {
           // do stuff after foo() has ran
        }
    }
Run Code Online (Sandbox Code Playgroud)

基本上,我希望foo()被要求运行或Child类不运行并返回错误或重定向到不同的页面.我可以调用该函数,但我想知道在扩展父类时是否可以使它成为一个要求.

php parent-child

0
推荐指数
1
解决办法
1432
查看次数

标签 统计

php ×2

kohana ×1

parent-child ×1