user3301561
user3301561

Reputation:

Error: The view for AppController::index() was not found

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

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

Upvotes: 0

Views: 2635

Answers (1)

arilia
arilia

Reputation: 9398

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\Users\register.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

Upvotes: 2

Related Questions