1. Controller as suffix, inherit from Yii\web\controller
2. Action is prefixed with action, public access adornment
3. Controller ID go to the class name suffix, all to lowercase, if the hump name more than one word, to the middle bar separated
4. Action ID go to prefix, all to lowercase, if the hump name more than one word, to the middle bar separated.
5. How the route points to the action Controller ID, action ID
6.URL access rule index.php?r= routing parameters using & parameter = value method
7. The default Action ID index is defined in Yii\base\controller:: $defaultAction
URL generation
A demonstration of how the URL helper class works
Use Yii\helpers\url;
Other action in the same controller
Echo url::toroute ([' Update ', ' id ' = ' 1 ']);//If there are no arguments, you can pass character channeling, do not need an array
Action for different controllers (same module)
echo url::toroute (' Post/index ');
Absolute path (you can jump out of the current module, if you start the module, you need to add the module ID in front)
echo url::toroute ('/site/index ');
Action that consists of multiple words in the current controller, such as Actionuserinfo
echo url::toroute (' User-info '); Controller Similar
URL with a domain name
echo url::toroute (' Site/index ', true);
Route aliases
echo url::toroute (' @register ');//Routing alias, you need to register aliases first, such as Yii::setalias (' @register ', ' site/register ');
Stitching image, CSS, etc.
Echo Url::base (); /project/web
Ehco Url:base (TRUE); Http://localhost/project/web
Echo url::to (); Empty is the time to return the current URL, including the parameter
echo url::to (array)//equivalent to Url::toroute (array)
Echo url::to ()
Jump
return $this->redirect ([' foot-bar/user-info ']);
Route rewriting
Open the config file in web.php.
/*
' Urlmanager ' = [
' Enableprettyurl ' = true, //remove? r=
' Showscriptname ' = False, //Remove index.php requires Apache to open rewrite module and Add. htaccess
' Rules ' = [
],
],
*/
And Apache opens the rewrite module and adds the. htaccess
Small point:
Ajax requests with renderpartial (do not load the tail of the head), usually with render on the line
Controllers and routes