在yii2 basic中调用控制器时出错

时间:2018-05-24 04:25:21

标签: php yii2

我在文件夹控制器yii basic

中创建这样的控制器
 <?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;

class HelloController extends Controller
{

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public function actionIndex()
    {
        echo "Hello World";
    }

    public function actionPosts($id=0, $category="all")
    {
        echo "Sedang menampilkan postingan dengan id: ".$id;
    }

    public function actionPostComments($id)
    {
        echo "Sedang menampilkan komentar dari postingan dengan id: ".$id;
    }

    public function actionUserPosts($user_id, $bulan, $tahun)
    {
        echo "Sedang menampilkan daftar postingan dari user dengan id ".$user_id." dengan arsip ".$bulan." / ".$tahun;
    }
}

但是当我尝试使用此链接调用函数actionUserPosts时

http://localhost/hello-yii/web/index.php?r=hello/user-posts?user_id=10&bulan=2&tahun=2017

结果未找到(#404)

这有什么问题?

1 个答案:

答案 0 :(得分:3)

像这样更改你的网址

http://localhost/hello-yii/web/index.php?r=hello/userPosts&user_id=10&bulan=2&tahun=2017

?只在第一次使用变量传递到url然后&amp;登录。