1
votes

I'm new in cakePhp, I've been following a tutorial and (in the tutorial) I created an user table called users, in my database(follow the naming conventions) and everything worked well, but in my project I created a table with a different name called usuarios then, I created the model, view and controller files, I created a file called "login.ctp" with the respective form,and in AppController.php I put this code :

class AppController extends Controller {

    public $helpers = array('Html','Form','Session');
    public $components = array('Session','Auth'=>array(
                                            'controller'=>'usuarios',
                                            'action'=>'login'
                                                    )

                               );

    public function beforeFilter(){
        $this->Auth->Allow('index');
    }
}

And inside the usuariosController.php I added this code:

public function logout(){
        $this->Auth->logout();
        $this->redirect('Pensums/index');
    }

    public function login(){
        if($this->request->is('post')){
            if($this->Auth->login()){
                return $this->redirect($this->Auth->redirecturl());
            }
        $this->Session->setFlash(_('Invalid username or password, please try again'));
        }
    }

but I receive this error from server:

Missing Controller

Error: UsersController could not be found.

Error: Create the class UsersController below in file: app\Controller\UsersController.php

is something missing? please help.

1

1 Answers

3
votes

UsersController is the default controller than handles the login. This is where it tries to go when you are not logged in.

Based on the pasted code, you seem to want to change that to UsuariosController

If UsuariosController is properly created and it has the login method, try to change the $components property from AppController to:

public $components = array(
    'Session',
    'Auth' => array(
        'loginAction' => array(
            'controller' => 'usuarios',
            'action' => 'login'
            )
        )
    );

When not logged in, it will redirect you to /usuarios/login