如何在 Yii2 中执行 create/access 操作?

How to create/access action in Yii2?

我想在特定 url ... /index.php?r=site%2FChildPage.

处呈现名称为 ChildPage.php 的视图文件

我写了一个小视图并在我的SiteController Class中添加了方法:

public function actionChildPage()
    {
        return $this->render('ChildPage');
    } 

我是不是忘记了什么?我的所有其他页面都在工作,但在此页面上出现错误:

Not Found (#404)
Page not found. 

阅读更多关于 creating actions 的信息:

By default, action IDs should contain these characters only: English letters in lower case, digits, underscores, and hyphens. (You can use hyphens to separate words.) For example, view, update2, and comment-post are all valid action IDs, while view? and Update are not.

The names of the action methods are derived from action IDs according to the following procedure:

  • Turn the first letter in each word of the action ID into upper case.
  • Remove hyphens.
  • Prepend the prefix action.

您应该简单地使用以下路线:site/child-page