View path cannot be displayed in Yii

Asked

Viewed 42 times

-1

Good afternoon.

I am learning the development of the YII PHP framework

I’m following a tutorial, in which the person shows how to create the route and how to create it.

I created my controller called Hellocontroller inside the controllers folder

   <?php


namespace app\controllers;
use yii\web\Controller;

class HelloController extends Controller
{
    public function actionSaySonething()
    {
        return $this->render('teste',[

        ]); // TODO: Change the autogenerated stub
    }
}

Ai in the views folder I created a folder named hello with a file called test.php

php test.

<?php

echo 'oi';

I noticed that routes are called that way:

http://localhost/basic/web/index.php?r=site%2Flogin 

and works with the files that comes with Yii, now when I put

http://localhost/basic/web/index.php?r=hello%2Fteste

can’t find.

1 answer

0


The route in Yii is set by default to be called as follows controlador/ação or modulo/controlador/ação.
In this your first example:

http://localhost/basic/web/index.php?r=site%2Flogin 

The route is the controller site and action is the login, if you look at the SiteController there will be an action called login.
In the second example:

http://localhost/basic/web/index.php?r=hello%2Fteste

You are requesting action teste of the controller hello, that is the problem the action declared is the SaySonething and requesting the teste that doesn’t exist.
The solution to the problem is to put in the url controlador/ação as follows:

http://localhost/basic/web/index.php?r=hello%2Fsay-sonething

Browser other questions tagged

You are not signed in. Login or sign up in order to post.