yii2 framework to create controllers and templates

1. Create the MineController.php controller under yii2-app-basic\controller

2.MineController.php code

<?php


namespace app\controllers;

use yii\web\Controller;

class MineController extends Controller
{

    public function actionHello(){

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

    }

}

3. Create the mine folder under yii2-app-basic\views, and create hello.php under the mine folder

4.hello.php code

<?php

?>

<h2>hello</h2>

5. Running effect

6. Some precautions, when routing access 

http://localhost/yii2-app-basic/web/index.php?r=mine%2Fhello

The mine in front of %2F corresponds to the name of the controller MineController.php Mine (name the controller in uppercase, but lowercase when routing access)

The hello behind %2F represents the actionHello() method of the MineController.php controller. The method name is the camel case naming rule, and the action is the method prefix 

 

Guess you like

Origin blog.csdn.net/zhunju0089/article/details/103506834