【问题标题】:Yii2 redirect 404 Page not foundYii2重定向404页面未找到
【发布时间】:2016-10-25 20:16:41
【问题描述】:

我在 view/stock/three.php 中有自定义页面(我制作的),我在 StockController 中渲染它,我尝试使用

从 view/site/shop.php 打开它
<div class="pager "><a href="<?= Yii::$app->urlManager->createUrl(['/stock/three']) ?>">3</a></div>

但我得到 Not Found (#404) Page not found. 。 (我没有忘记设置“使用网址”) 我也尝试从 SiteController 重定向它:

public function actionThree() {
     return $this->redirect(['/stock/three']);
}

但也没有工作,仍然得到错误代码 404

【问题讨论】:

  • 你的 UrlManager 配置是什么?

标签: view controller yii2-basic-app


【解决方案1】:

也许您在views/stock 文件夹中没有“three.php”文件,或者在“stock”之前没有正斜杠(“/”)。

【讨论】:

  • 我在 views/stock 文件夹中创建了“three.php”文件,我尝试在“stock”之前使用和不使用斜杠,这两种方式都不起作用
【解决方案2】:

试试这个

public function actionThree() {
     return $this->redirect(['stock/three']);
}

【讨论】:

    【解决方案3】:

    我为我编写的页面制作了新的模型和新的控制器:

    public function actionThree() {
        return $this->render('three');
    }
    

    然后

    <div class="pager "><a href="<?php echo Url::to(['pages/three']) ?>">3</a></div>
    

    工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-31
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 2016-11-21
      相关资源
      最近更新 更多