doue1925 2016-01-17 13:24
浏览 521
已采纳

在Yii2中找不到(#404)

I am starting with Yii2, already installed XAMPP, created a basic project named 'yiidemo' with the help of Yii2 project template. Then access Gii by this URL http://localhost:8080/yiidemo/web/index.php?r=gii to generate a sample controller 'greeting', but when I click on 'Try it' link, it is showing me following error message (url is http://localhost:8080/yiidemo/web/index.php?r=greeting ):

Not Found (#404)

This is the controllers\greetingController's code:

<?php

namespace app\controllers;

class greetingController extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->render('views/index');
    }

}

And this is the views\greeting\index.php code:

<?php
/* @var $this yii\web\View */
?>
<h1>greeting/index</h1>

<p>
    You may change the content of this page by modifying
    the file <code><?= __FILE__; ?></code>.
</p>

Can any body suggest how to get it worked with Yii2 hello world example.

  • 写回答

2条回答 默认 最新

  • doudao9915 2016-01-17 13:50
    关注

    The Controllers need to be all CamelCase and start with a capital letter. So in your case, GreetingController (both class and file).

    And in your action use:

    return $this->render('index');
    

    See more about how to use this method here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数