Luke
Luke

Reputation: 658

"Action not defined in AppController" error when accessing a different controller with default route

I'm super new to CakePHP so I have a feeling that I'm probably just doing something silly, but I've been stuck on a problem:

Following the tutorials, I created a controller called UsersController in cakephp/app/Controller/UsersController.php, and a model in cakephp/app/Model/User.php that corresponds to a users table in my database. (Also created a view) From what I understand, the default route to this should be:

mysite.com/cakephp/app/users

However, when I go to that URL, I get the error

The action users is not defined in controller AppController

If I add this to AppController...:

public function users(){
    $this->redirect(array('controller' => 'users', 'action' => 'index'));
}

...it will go to the right controller and everything is dandy, but I know that isn't the way it's supposed to work. Any idea what I might be doing wrong here?

Upvotes: 1

Views: 6298

Answers (1)

Dave
Dave

Reputation: 29121

For your example, it should just be www.mysite.com/users This will look for an index action in the users controller.

The "normal" url is www.mysite.com/controller/action/variables

You don't need to define anything in the AppController (for this example).

Upvotes: 1

Related Questions