我有一个 cakePHP 应用程序,我希望我的登录和注册表单在我遵循本教程的同一页面中:http: //bakery.cakephp.org/articles/RabidFire/2010/06/26/multiple-forms -per-page-for-the-same-model并且我能够使注册部分工作但登录部分不起作用我收到以下错误:“缺少数据库表错误:未找到模型 Tbluserlogin 的表 tblforumuserlogins在数据源默认值中。” 这是我正在使用的控制器:
class TblusersController extends AppController {
public function signup() {
$this->loadModel('Tbluser');
$this->loadModel('Tbluserlogin');
if (!empty($this->data)) {
if (isset($this->data['Tbluser'])) { // Check if the signup Form was submitted
$this->Session->setFlash("SignUp Form was submitted.","notif");
} else if (isset($this->data['Tbluserlogin'])) { // Check if the login Form was submitted
$this->Session->setFlash("Login Form was submitted.","notif");
}
}
}
}
?>
我使用的模型是:
Tbluser.php
<?php
class Tbluser extends AppModel{
public $validate = array(
'username'=>array(
array(
'rule'=>'alphaNumeric',
'allowEmpty'=>false,
'message'=>'Invalide Username!'
),
array(
'rule' => array('minLength', '4'),
'message' => 'Username has to be more than 3 chars'
),
array(
'rule'=>'isUnique',
'message'=>'Username already taken!'
)
),
'password' => array(
array(
'rule' => 'alphaNumeric',
'allowEmpty'=>false,
'message' => 'Password must be AlphaNumeric!'
),
array(
'rule' => array('minLength', '4'),
'message' => 'Username has to be more that 3 chars'
),
array(
'rule' => array('confirmPassword', 'cakehashedpassword'),
'message' => 'Passwords do not match'
)),
'email'=>array(
array(
'rule'=>array('email',true),
'required'=>true,
'allowEmpty'=>false,
'message'=>'Invalide email adress!'
),
array(
'rule'=>'isUnique',
'message'=>'Mail adress already taken!'
)
)
);
}
?>
Tbluserlogin.php 模型:
<?php
class Tblforumuserlogin extends Tblforumuser{
}
?>
我的视图文件是“signup.ctp”
<h4>Sign up</h4>
<div><?php echo $this->Session->flash();?></div>
<?php
echo $this->Form->create("Tblforumuser", array('url' => '/Tblusers/signup'));
echo $this->Form->input('username' ,array('label'=>'Username<b style="color:red;">'));
echo $this->Form->input('password' ,array('label'=>'Password<b style="color:red;">','type' => 'password'));
echo $this->Form->input('email' ,array('label'=>'Email<b style="color:red;">'));
echo $this->Form->end('Register');
?>
<h4>Log in to Ohyeahhh</h4>
<div><?php echo $this->Session->flash(); ?></div>
<?php echo $this->Form->create("Tbluserlogin", array('url' => '/Tblusers/signup')); ?>
<?php echo $this->Form->input('username' ,array('label'=>"Username :")); ?>
<?php echo $this->Form->end('Login'); ?>
谢谢你。