【问题标题】:how to extend kohana user auth module如何扩展 kohana 用户身份验证模块
【发布时间】:2012-01-26 05:13:19
【问题描述】:

所以我正在使用 kohana 用户模块,我想扩展我的注册页面,现在它添加了用户名、电子邮件和密码,但我想添加一些额外的字段,但我找不到哪里可以我做。

我找到了function action_register 导致Auth::instance()->register($_POST, true); 所以我找到了这个function register($fields) 导致$user = ORM::factory('user'); 和$user->create_user($fields, array() 所以我被困在这里的某个地方,我什至不确定我是否要去正确的道路...

【问题讨论】:

    标签: php kohana kohana-auth


    【解决方案1】:

    只需在 application/classes/model 文件夹下创建 user.php 文件并将其放入:

    <?php
    
    defined('SYSPATH') or die('No direct access allowed.');
    
    class Model_User extends Model_Auth_User
    {
       public function create_user($values, $expected)
       {
          // Your definition of the function
       }
    }
    

    检查注册功能后,这里是其他字段的地方(第22-27行):

    $user->create_user($fields, array(
                                    'username',
                                    'password',
                                    'email',
                                    'user_type',
                                    'other field',
                                    'other field2',
                            ));
    

    当然,您的表中需要有other_field 和other_field2。

    【讨论】:

    • 这是完全错误的,我已经完成了一切我只需要找到实际查询的执行位置,这样我就可以添加额外的字段
    • 扩展了create_user 函数,那么如果你已经让一切都飞起来了?
    • 那个函数看起来像这样pastebin.com/fqk61PH7,这对我来说毫无意义..
    • 这很有意义。它通过调用 ORM 函数来创建用户——首先是值,然后是创建。它还检查密码是否不为空。我建议您阅读 ORM 教程以了解基础知识。
    • 好的,我如何发送额外的值,因为我已经在数据库中创建了新字段,我只需要添加这些值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 2022-09-29
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多