我試圖在URL中傳遞ID。我很難做到這一點。所以,我正在瀏覽像Larry Ullman - URL Routing這樣的教程。URL路由 - yii-basic-app - Yii2
我的問題是:我創建了confirm.php頁面並創建了一個控制器,但是像NOTFOUND(#404)這樣的錯誤即將到來。
SiteController.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>',
],
],
confirm.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)
i之後得到這個錯誤,我添加幾個碼配置/ 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頁面。
怎麼辦?我沒有想法。請幫我解決這個問題。
添加該代碼,你可以發佈確認的'位置。 php' – GAMITG
yii2-app-basic/views/site/confirm.php Mr @gamitg –
你在'w中添加'.htaccess'文件eb'文件夾? – GAMITG