doubiaode0460 2014-04-02 13:34
浏览 56
已采纳

错误:找不到AppController :: index()的视图

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

Controller Class:

<?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
";
         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);
        }
}
?>

Model class:

 <?php
    class usersform extends AppModel
    {

    }

    ?>

View Class:

<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:

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

  • 写回答

1条回答 默认 最新

  • dqudtskm49788 2014-04-02 13:58
    关注

    I think you are making a bit of confusion.

    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).

    So I will rename your model into User

     class User extends AppModel
    

    then your controller into UsersController

    class UsersController extends AppController
    { 
        public $helpers=array('Html','Form','Session');
        public $components=array('Session');
        public function index(){
        }
        public function register()
    
        \\ and so on....
    }
    

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

     \app\View\Usersegister.ctp
    

    the url now is something like

    localhost/project/UserRegisterForm/users/register 
    

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程