Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 131.7MB ·虚拟内存 1372.6MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
Yii应用程序处理所请求的URL时,首先将URL解析为路由。然后,为了处理请求,这条路由被用来实例化相应的控制器动作。这个过程被称为 路由 。相反的过程称为URL创建。该 urlManager 应用组件负责路由和URL创建。它提供了两种方法 -
该 urlManager 应用组件支持两种格式的URL -
要启用漂亮的URL格式并隐藏条目脚本名称,请按照以下步骤操作 -
第1步 - 以下面的方式修改 config / web.php 文件。
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) -
//this is required by cookie validation
'cookieValidationKey' => 'ymoaYrebZHa8gURuolioHGlK8fLXCKjO',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true
],
'db' => require(__DIR__ . '/db.php'),
],
'modules' => [
'hello' => [
'class' => 'app\modules\hello\Hello',
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
?>
我们刚刚启用了 漂亮的URL格式 ,并禁用了条目脚本名称。
第2步 - 现在,如果您 在Web浏览器的地址栏中输入 http:// localhost:8080 / site / about ,您将看到相应的网址。

注意,URL不再是 http:// localhost:8080 / index.php?r = site / about 。
要更改应用程序的默认路由,您应该配置 defaultRoute 属性。第1步 - 以下面的方式修改 config / web.php 文件。<?php $params = require(__DIR__ . '/ ...