使用cake php进行多用户注册不起作用
我想尝试注册一个用户,并根据他们所属的用户类型解除绑定 我已经在数据库的user表中为usertype设置了一个enum字段 这是我的登记表使用cake php进行多用户注册不起作用,php,sql,cakephp,registration,Php,Sql,Cakephp,Registration,我想尝试注册一个用户,并根据他们所属的用户类型解除绑定 我已经在数据库的user表中为usertype设置了一个enum字段 这是我的登记表 <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ echo $this->form->create('Users', array('action' => 'regist
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
echo $this->form->create('Users', array('action' => 'register'));
echo $this->form->input('Username');
echo $this->form->input('Password', array('type' => 'password'));
echo $this->form->input('Confirm Password', array('type' => 'password'));
echo $this->form->input('Name');
echo $this->form->input('Surname');
$options = array ( '1' => 'Tester',
'2' => 'Developer',
'3' => 'Config',);
$attributes = array('separator'=>'<br />','legend' => false);
echo $this->form->radio('Usertype', $options, $attributes);
echo $this->form->end('Create User');
echo $this->Html->link('I have an account already', '/users/login', array('class' => 'button', 'target' => '_blank'));
?>
这是我的用户控制器
<?php
class UsersController extends AppController {
public $name = 'Users';
public $helpers = array('Html','form');
public function register(){
$this->loadModel("Users");
if ($this->request->is('post')) {
if ($this->user->save($this->request->data)) {
$this->Session->setFlash(__('Your user profile has been created.'));
return $this->redirect(array('action' => 'index'));
} else {
debug($this->validationErrors); die();
}
// $this->Session->setFlash(__('Problem creating your user profile,try again'));
// return $this->redirect(array('action' => 'register'));
}
}
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('register');
}
public function isAuthorized($user) {
if ($user['usertype'] == '1') {
$this->redirect($this->Auth->redirect(array('controller' => 'software', 'action'=>'addsoftware')));
} else if ($user['usertype'] == '2') {
$this->redirect($this->Auth->redirect(array('controller' => 'user', 'action'=>'addsoftware')));
}elseif ($user['usertype'] == '3') {
$this->redirect($this->Auth->redirect());
}
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your username/password combination was incorrect');
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->User->find('all'));
}
}
?>
请帮忙 你的错误是什么?注意你的外壳和惯例。您的代码中似乎有很多问题,例如,
$this->form->create('Users'
应该是$this->form->create('User'
)。另外,确认密码
由于字段名无效,它应该是确认密码
。