我正在开发一个简单的应用程序,但它会抛出错误消息。
控制器类:
<?php
class RegisterController extends AppController
{
public $helpers=array('Html','Form','Session');
public $components=array('Session');
public function index(){
}
public function register()
{
echo "inside fun index inside controller usersform, this function adds data to the database taking values from the registration form\n";
if( !empty($this->request->data ))
{ //pr($this->request->data);exit;
$username=$this->request->data['username'];
$password=$this->request->data['password'];
$email=$this->request->data['email'];
$first_name=$this->request->data['first_name'];
$last_name=$this->request->data['last_name'];
$savedData=array();
$savedData['usersform']=array( 'username'=>$username,
'password'=>$password,
'email'=>$email,
'first_name'=>$first_name,
'last_name'=>$last_name
);
if($this->usersform->save($savedData))
{ //echo "/ndata is saved in the database";
$this->Session->setFlash("data is now saved in database, you can now login to your account");
$this->redirect(array('action'=>'login'));
}
else { $this->Session->setFlash("Unable to save data");
}
}
}
public function login()
{
echo "inside func login inside controller usersform, this func would check name an password that the usersform has filled and match it against database records";
if(!empty($this->request->data)){
$username=$this->request->data['username'];
$password=$this->request->data['password'];
$searchData=$this->Teacher->find('first',array('conditions'=>array('username'=>$username, 'password'=>$password)));
//echo '<pre>';
//pr($searchData);exit;
if(empty($searchData))
{
//$message = 'Not Found';
$this->Session->setFlash("could not find data matching ur login details");
}
else
{
//$message = 'Login Successfully';
$this->Session->write('username',$username);
$this->Session->setFlash("congrats, you have successfully logged in");
$this->redirect(array('controller'=> 'usersform', 'action'=>'welcome'));
}
}
}
public function welcome()
{ echo "inside the welcome func inside teachers controller";
echo $this->Session->read('username');
// $this->Session->setFlash("welcome to your account" .$username);
}
}
?>
模特课程:
<?php
class usersform extends AppModel
{
}
?>
查看课程:
<form action="<?php echo $this->html->url(array('controller'=>'Teachers', 'action'=>'index')); ?>" method="POST">
Username:<input type="text" name="username" size="30">
password:<input type="password" name="password" size="30">
email:<input type="text" name="email" size="10">
First_Name:<input type="text" name="First_Name" size="30">
Last_Name:<input type="text" name="Last_Name" size="30">
<input type="submit" name="submit" size="15">
</form>
它会抛出一条错误信息:
缺少视图 错误:找不到AppController :: index()的视图。 错误:确认您已创建文件:D:\ xampp \ htdocs \ project \ UserRegisterForm \ app \ View \ App \ index.ctp
答案 0 :(得分:2)
我认为你有点混乱。
通常你有一个User
模型(包含有关用户的信息的模型)及其控制器通常命名为UsersController
(注意复数形式)。 UsersController
包含您可以对用户执行的所有操作(即login
,register
等等。
因此,我会将您的模型重命名为User
class User extends AppModel
然后您的控制器进入UsersController
class UsersController extends AppController
{
public $helpers=array('Html','Form','Session');
public $components=array('Session');
public function index(){
}
public function register()
\\ and so on....
}
您的视图应与操作的名称相同,并且位于View \ Users目录中:
\app\View\Users\register.ctp
现在的网址类似于
localhost/project/UserRegisterForm/users/register
或(如果您没有启用.htaccess)
localhost/project/UserRegisterForm/index.php/users/register
编辑:我没有查看您的控制器代码。也许你在那里犯了很多错误,但我认为这不是解决你所有错误的目的