M_Idrees
M_Idrees

Reputation: 2182

Not Found (#404) in Yii2

I am starting with Yii2, already installed XAMPP, created a basic project named 'yiidemo' with the help of Yii2 project template. Then access Gii by this 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 ):

Not Found (#404)

This is the controllers\greetingController's code:

<?php

namespace app\controllers;

class greetingController extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->render('views/index');
    }

}

And this is the views\greeting\index.php code:

<?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>

Can any body suggest how to get it worked with Yii2 hello world example.

Upvotes: 0

Views: 19637

Answers (3)

vinod
vinod

Reputation: 2880

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

Upvotes: 1

aalesund
aalesund

Reputation: 323

Check that the file is saved as GreetingsController.php and not just GreetingsController (without .php) Although this is not the mistake you made it still produces the same error message.

Upvotes: 0

Clyff
Clyff

Reputation: 4076

The Controllers need to be all CamelCase and start with a capital letter. So in your case, GreetingController (both class and file).

And in your action use:

return $this->render('index');

See more about how to use this method here.

Upvotes: 6

Related Questions