Yii's MVC

Source: Internet
Author: User
Tags yii

One: MVC


Two: Yii Routing information

Http://192.168.85.129/index.php?r=user%2Findex

This is the routing address information for a YII open page. Index.php for the Ingress address (also known as the portal script) in the/web/index.php portal script mainly completes the following operations:

    • Define global constants, register the Composer autoloader, include [[Yii]] class files, load application configurations, create an application instance and configure it, and Invoke [[Yii\base\application::run ()]] to process the request.
<?phpdefined (' yii_debug ') or define (' Yii_debug ', true);d efined (' yii_env ') or define (' yii_env ', ' dev ');//Register Composer Auto loader require (__dir__. ‘/.. /vendor/autoload.php '),//contains YII class file require (__dir__. ‘/.. /vendor/yiisoft/yii2/yii.php ');//load application configuration $config = require (__dir__. ‘/.. /config/web.php ');//Create, configure, and run an application (new Yii\web\application ($config))->run ();

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5B/3D/wKioL1UDh2_QC7nGAAGOGBd8nyY579.jpg "title=" 1.png " alt= "Wkiol1udh2_qc7ngaagogbd8nyy579.jpg"/>


? R: For the meaning of the route, that is, from the entrance into which to route to which page to go.


User%2findex:%2f equivalent to/escaped, the intention is user/index. So this path can also be written as:

Http://192.168.85.129/index.php?r=user/index

User as Controller ID

Index is the action ID



Three: Controller

The controller is part of the MVC pattern and is an object that inherits the [[Yii\base\controller]] class and is responsible for processing requests and generating responses. Specifically, the controller analyzes the request data and transmits it to the model, transmits the model result to the view, and finally generates the output response information after the control is taken over from the application body.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5B/43/wKiom1UDitGQ3iU9AACiWmQdqw4516.jpg "title=" 2.png " alt= "Wkiom1uditgq3iu9aaciwmqdqw4516.jpg"/>

The controller has the operation composition, a controller can have many operation composition

Namespace app\controllers;use yii;use app\models\post;use yii\web\controller;use yii\ web\notfoundhttpexception;class postcontroller extends controller{     Public function actionview ($id)     {          $model  = post::findone ($id);        if  ($model  === null)  {            throw  new notfoundhttpexception;        }         return  $this->render (' View ', [              ' model '  =>  $model,         ]);     }    public function actioncreate ()        {         $model  = new Post;         if  ($model->load (Yii:: $app->request->post ())  &&  $model->save ())  {            return  $this->redirect ( [' View ',  ' id '  =>  $model->id]);         } else {             return  $this->render (' Create ', [                  ' model '  =>  $model,             ]);         }    }}

Controllerid naming rules

For example Usernamecontroller: For a control ID, it is named username

Usernamecontroller: Its name is User-name

The action defined after the function is the action ID name is the content after the action.

ActionId naming rules as above.



This article is from the "Slayer" blog, make sure to keep this source http://slayer.blog.51cto.com/4845839/1620427

Yii's MVC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.