У меня возникла странная проблема с проверкой имени пользователя (как следует из заголовка) в представлении редактирования, из-за которого я не могу сохранить форму.У меня нет ввода в этом представлении для имени пользователя, так почему это проверяется (и не выполняется)?
Проверка выполняется следующим образом:
var $validate = array(
'username' => array(
'empty' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Username is required',
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This username has already been taken'
),
'pattern' => array(
'rule' => array('custom','/[a-zA-Z0-9\_\-]{6,}$/i'),
'message' => 'Must be 6 characters or longer with no spaces',
),
'length' => array(
'rule' => array('maxLength', 15),
'message' => 'Please keep username under 15 characters',
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Username cannot be empty',
)
);
функция редактирования ниже:
function edit($id = null) {
$this->set('title_for_layout', 'Edit Profile');
unset($this->User->validate['email']['email']);
unset($this->User->validate['username']);
if($this->Auth->user('id')==$id) {
$this->set('user', $this->User->read(null, $id));
} else {
$this->Session->setFlash(__('You are not authorised to edit other member profiles', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('Your profile has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Your profile could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->User->read(null, $id);
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
Я сбросил username
, который позволяет мне только сохранить форму, но это не может быть правильным способом для этого.Может ли кто-нибудь пролить свет на это?
Большое спасибо!