Validation kohana ORM用户模型可以';t验证其他用户行,例如姓名等

Validation kohana ORM用户模型可以';t验证其他用户行,例如姓名等,validation,kohana,admin,add,Validation,Kohana,Admin,Add,在哪些方面进行了更改,以便进行检查?我不想为兼容性重复字段检查密码字段 Kohana用户控制器中的“我的添加”功能 public function action_add() { $title = 'Add User'; $this->template->title = $title; $this->template->content = View::factory('action/users/add')

在哪些方面进行了更改,以便进行检查?我不想为兼容性重复字段检查密码字段

Kohana用户控制器中的“我的添加”功能

public function action_add() {
        $title = 'Add User';
        $this->template->title = $title;
        $this->template->content = View::factory('action/users/add')
                ->bind('title', $title)
                ->bind('message', $message)
                ->bind('errors', $errors);

        if (HTTP_Request::POST == $this->request->method()) {
            try {

                // Create the user using form values
                $user = ORM::factory('user')->create_user($this->request->post(), array(
                    'username',
                    'password',
                    'email',
                    'last_name',
                    'first_name',
                    'middle_name'
                        ));

                // Grant user login role
                $user->add('roles', ORM::factory('role', array('name' => 'login')));

                // Reset values so form is not sticky
                $_POST = array();

                Session::instance()->set('message', "You have added user '{$user->username}' to the database");
                Request::current()->redirect('/admin/' . $this->request->param('lang') . '/action/users' );
            } catch (ORM_Validation_Exception $e) {

                // Set failure message
                $message = 'There were errors, please see form below.';

                // Set errors using custom messages
                $errors = $e->errors('models');
            }
        }
    }

我认为可以直接使用ORM::create()方法

ORM::create_user()所做的就是验证密码,这正是您想要跳过的

所以你应该用像

  $user = ORM::factory('user')->values($this->request->post(), array(
                'username',
                'password',
                'email',
                'last_name',
                'first_name',
                'middle_name'
                    ))->create();
避免调用create_用户,您也将避免密码长度验证,因此通常您将在模型中添加此规则,但由于密码get hash应该在控制器中处理,因此我发现您没有对$POST数据使用任何验证或过滤器,我建议您使用Validator对象

使用它可以限制密码长度