【问题标题】:Yii create first test pageYii 创建第一个测试页面
【发布时间】:2015-09-21 16:22:39
【问题描述】:

我是 yii 新手,我已经设置了示例 yii 演示应用程序(默认)n 现在我想创建新页面,但我收到 404 错误,以下是我遵循的步骤。

1) 在站点控制器中创建了新操作

public function actionTest()
{
  $this->render('test');
}

2) 在视图文件夹 test.php

中创建新页面
echo "test";

3) 在ma​​in.php(配置文件)中添加以下代码

'urlManager' => array(

      'urlFormat' => 'path', 

      'showScriptName' => false,

      'caseSensitive' => false,

      'rules' => array(

      'test' => 'site/test',

      ),  
),

4) 当我使用 URL 运行应用程序时

http://localhost/YiiTest/test 

然后得到错误

The requested URL /YiiTest/test was not found on this server. 

【问题讨论】:

  • 我没有测试,但是你不会错过设置为 true 的 enablePrettyUrl 吗?
  • 您是否将文件 test.php 放在 protected/views/site 文件夹中?还有你的 URL,localhost/folder/site/test?
  • 是的@AlejandroQuiroz 我已将我的 test.php 放在 protected/views/site 文件夹中,但它仍然无法正常工作
  • 在浏览器中输入 localhost/YiiTest/site/test 并尝试加载它

标签: php yii yii2 yii-url-manager


【解决方案1】:

确保您已重写您的 .htaccess 文件 link

【讨论】:

  • 感谢重播@Double,我有带有重写规则的.htaccess 仍然无法在#RewriteCond %{HTTP_HOST} 上运行RewriteEngine!^www\。 #RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [R=301,L] # 如果目录或文件存在,直接使用 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 否则将其转发到 index.php RewriteRule 。 index.php RewriteEngine On RewriteCond %{HTTP_HOST} !^www\。重写规则 ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]
  • 模块重写是否启用。
  • 是的,它正在工作并显示默认 yii webapp 内容的内容
  • 改变 'test' => 'site/test', By array('test' => 'site/test', ),
  • HI 厌倦了上面的解决方案,现在我得到了不同的错误 The requested URL /Server/htdocs/FastBit/YiiTest/index.php was not found on this server.
猜你喜欢
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-14
  • 2019-10-30
相关资源
最近更新 更多