错误:找不到AppController :: index()的视图 [英] Error: The view for AppController::index() was not found

查看:3836
本文介绍了错误:找不到AppController :: index()的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的应用程序,但它会抛出一条错误消息。

I am developing a simple application but it throws an error message.

控制器类:

<?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-&gt;request-&gt;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 '&lt;pre&gt;';
        //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-&gt;Session-&gt;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>

它会抛出如下错误信息:

It throws an error message like this:

缺少视图
错误:找不到AppController :: index()的视图。
错误:确认您已创建文件:D:\xampp\htdocs\project\UserRegisterForm\app\View\App\index.ctp

Missing View Error: The view for AppController::index() was not found. Error: Confirm you have created the file: D:\xampp\htdocs\project\UserRegisterForm\app\View\App\index.ctp


推荐答案

我认为你有些混乱。

你有一个 User 模型(该模型包含关于用户的信息),它的控制器通常命名为 UsersController 形成)。 UsersController 包含您可以对用户执行的所有操作(即登录 / code>等等)。

Usually you have a User model (the model containing informations about a User) and its controller usually named UsersController (note the plural form). The UsersController holds all the actions you can do on a User (i.e. login, register and so on).

所以我将你的模型重命名为 User >

So I will rename your model into User

 class User extends AppModel


$ b b

然后你的控制器到 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目录中:

Your view should have the same name of the action and be located into the View\Users directory:

 \app\View\Users\register.ctp

现在的url就像

localhost/project/UserRegisterForm/users/register 

或(如果您没有启用.htaccess)

or (if you don't have .htaccess enabled)

localhost/project/UserRegisterForm/index.php/users/register 

编辑:我没有看你的控制器代码。也许你在那里也犯了很多错误,但我认为这不是这个答案的目的解决所有的错误

edit: I did not look into your controller code. Probably you are making a lot of mistakes there too, but I think that's not the purpose of this answer resolve all of your errors

这篇关于错误:找不到AppController :: index()的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆