我试图在 URL 中传递 ID。我很难做到。因此,我正在阅读诸如Larry Ullman - URL Routing 之类的教程。
我的问题是:我创建了 confirm.php 页面并创建了一个控制器,但是出现了 NOT FOUND (#404) 之类的错误。
站点控制器.php
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\swiftmailer\Mailer;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\EntryForm;
use app\models\RegisterForm;
use app\models\LoginExecForm;
use app\models\ForgotPasswordForm;
class SiteController extends Controller
{
.
.
public function actionConfirm($id)
{
$id = Yii::$app->request->get('id');
return $this->render('confirm');
}
}
配置/web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => [
'<controller>/<action:\w+>.<_format>' => '<controller>/<action>',
'v1/<controller>/<action:\w+>.<_format>' => 'v1/<controller>/<action>',
],
],
确认.php
<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
use yii\bootstrap\Modal;
use yii\helpers\Url;
$this->title = 'Register';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
asd
</div>
错误出现 => 未找到(#404)
收到此错误后,我在config/web.php中添加了一些代码
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules'=>array(
'<controller:\w+>/<id:\d+>' => '/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '/',
'<controller:\w+>/<action:\w+>' => '/',
),
],
但是,现在的问题是每个页面都重定向到 index.php 页面。
该怎么办 ?我没有主意。请帮我纠正这个问题。