简体   繁体   English

使用默认路由访问其他控制器时,“在AppController中未定义操作”错误

[英]“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: 我是CakePHP的超级新手,所以我觉得我可能只是在做一些愚蠢的事情,但是我一直陷入一个问题:

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. 按照这些教程,我在cakephp / app / Controller / UsersController.php中创建了一个名为UsersController的控制器,并在cakephp / app / Model / User.php中创建了一个与数据库中的用户表相对应的模型。 (Also created a view) From what I understand, the default route to this should be: (也创建了一个视图)据我了解,到此的默认路由应为:

mysite.com/cakephp/app/users mysite.com/cakephp/app/users

However, when I go to that URL, I get the error 但是,当我转到该URL时,出现错误

The action users is not defined in controller AppController 未在控制器AppController中定义操作用户

If I add this to AppController...: 如果我将此添加到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? 知道我在这里可能做错了什么吗?

For your example, it should just be www.mysite.com/users This will look for an index action in the users controller. 对于您的示例,它应该只是www.mysite.com/users这将在users控制器中查找索引操作。

The "normal" url is www.mysite.com/controller/action/variables “常规”网址是www.mysite.com/controller/action/variables

You don't need to define anything in the AppController (for this example). 您无需在AppController中定义任何内容(对于此示例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM