在 Yii2 中找不到 (#404)
Not Found (#404) in Yii2
我开始使用 Yii2,已经安装 XAMPP,在 Yii2 项目模板的帮助下创建了一个名为 'yiidemo' 的基本项目。然后通过 URL http://localhost:8080/yiidemo/web/index.php?r=gii to generate a sample controller 'greeting', but when I click on 'Try it' link, it is showing me following error message (url is http://localhost:8080/yiidemo/web/index.php?r=greeting ):
访问 Gii
未找到 (#404)
这是 controllers\greetingController 的代码:
<?php
namespace app\controllers;
class greetingController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('views/index');
}
}
这是 views\greeting\index.php 代码:
<?php
/* @var $this yii\web\View */
?>
<h1>greeting/index</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
任何人都可以建议如何让它与 Yii2 hello world 示例一起工作。
Controller 必须全部是 CamelCase 并且以大写字母开头。因此,在您的情况下,GreetingController
(class 和文件)。
并在您的操作中使用:
return $this->render('index');
查看有关如何使用此方法的更多信息here。
检查文件是否保存为 GreetingsController.php 而不仅仅是 GreetingsController(没有 .php)
虽然这不是你犯的错误,但它仍然会产生相同的错误消息。
Check your apache config file and make sure web directory is allowing override or not
You can found config file in your ubuntu system here
sudo nano /etc/apache2/sites-enabled/000-default.conf
Few Linux system have config file on
sudo nano /etc/httpd/conf/httpd.conf
Just check your config file and replace AllowOverride None with AllowOverride All
For example
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After saving file changes just restart Apache server
我开始使用 Yii2,已经安装 XAMPP,在 Yii2 项目模板的帮助下创建了一个名为 'yiidemo' 的基本项目。然后通过 URL http://localhost:8080/yiidemo/web/index.php?r=gii to generate a sample controller 'greeting', but when I click on 'Try it' link, it is showing me following error message (url is http://localhost:8080/yiidemo/web/index.php?r=greeting ):
访问 Gii未找到 (#404)
这是 controllers\greetingController 的代码:
<?php
namespace app\controllers;
class greetingController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('views/index');
}
}
这是 views\greeting\index.php 代码:
<?php
/* @var $this yii\web\View */
?>
<h1>greeting/index</h1>
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
任何人都可以建议如何让它与 Yii2 hello world 示例一起工作。
Controller 必须全部是 CamelCase 并且以大写字母开头。因此,在您的情况下,GreetingController
(class 和文件)。
并在您的操作中使用:
return $this->render('index');
查看有关如何使用此方法的更多信息here。
检查文件是否保存为 GreetingsController.php 而不仅仅是 GreetingsController(没有 .php) 虽然这不是你犯的错误,但它仍然会产生相同的错误消息。
Check your apache config file and make sure web directory is allowing override or not
You can found config file in your ubuntu system here
sudo nano /etc/apache2/sites-enabled/000-default.conf
Few Linux system have config file on
sudo nano /etc/httpd/conf/httpd.conf
Just check your config file and replace AllowOverride None with AllowOverride All
For example
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After saving file changes just restart Apache server