【问题标题】:Error when call a controller in yii2 basic在 yii2 basic 中调用控制器时出错
【发布时间】:2018-05-24 04:25:20
【问题描述】:

我在文件夹 controllers 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)

这有什么问题?

【问题讨论】:

  • 找不到对象

标签: php yii2


【解决方案1】:

像这样更改您的网址

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

?仅在变量传入 url 然后 & 签名时才使用。

【讨论】:

  • 如果此答案对您有帮助,请点击右标志接受。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2016-08-11
  • 2015-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多