문제

The Model_Auth_User class in Kohana uses 'username', 'email','password' to create a new user what if i want it to take only 'email', 'password' and also modify the validation to validate 'email_confirm' instead of 'password_confirm'

도움이 되었습니까?

해결책

Finally i did it, All what I have to doe is to comment some lines which add the rules of validating user input open C:\xampp\htdocs\kohana\modules\orm\classes\Model\Auth\User.php and comment lines from 33:38 inclusive as following:

    public function rules()
{
    return array(
        //as we don't have a username we don't need to validate it!
        // 'username' => array(
        //  array('not_empty'),
        //  array('max_length', array(':value', 32)),
        //  array(array($this, 'unique'), array('username', ':value')),
        // ),
        'password' => array(
            array('not_empty'),
        ),
        'email' => array(
            array('not_empty'),
            array('email'),
            array(array($this, 'unique'), array('email', ':value')),
        ),
    );
}

You only keep the rules for validating what you need

다른 팁

Avoid changing of the system folder contents. Otherwise your changes will be lost after the next upgrade. The more correct approach is to override the validation rules.

In file application/classes/Model/user.php:

<?php
  class Model_User extends Model_Auth_User
  {
    public function rules()
    {
      $rules = parent::rules();
      unset($rules['username']);
      return $rules;
    }
  }
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top