What is the use of the actions function in the Controller in the YII framework? Is it just for verification?

Source: Internet
Author: User
What is the difference between him and such methods as actionIndex? What I saw in the Yii video tutorial is the difference between the verification code and the actionIndex method? What I saw in the Yii video tutorial is the verification code.

Reply content:

What is the difference between him and such methods as actionIndex? What I saw in the Yii video tutorial is the verification code.

For example, define an action through a file instead of defining it in the controller.

function actions(){       return array(            'edit'=>'application.controllers.post.UpdateAction',        );    }

For example:
Official example: In SiteController

public function actions()    {        return array(            // captcha action renders the CAPTCHA image displayed on the contact page            'captcha'=>array(                'class'=>'CCaptchaAction',                'backColor'=>0xFFFFFF,            ),            // page action renders "static" pages stored under 'protected/views/site/pages'            // They can be accessed via: index.php?r=site/page&view=FileName            'page'=>array(                'class'=>'CViewAction',            ),                        'search'=>array(                            'class'=>'ext.esearch.SearchAction',                            'model'=>'Post',                            'attributes'=>array('title', 'tags', 'content'),                        ),                           );    }

Directly through xxx? R = site/captcha has accessed the verification code!

For public operations, both AController and BController have an edit method, which can be placed in actions.

Thank you! :)
As the name suggests,actionIt is undoubtedly used to describe the action of the controller. GenerallyactionIndex, That is, the default action.
Example:

class PageController extends Controller{    public function actionIndex()    {        echo 'default action';    }}

When a user requests, the default action is triggered and the output isdefault action.
Of course, you can also define specificactionFor example:

class PageController extends Controller{    public function actionIndex()    {        echo 'default action';    }    public function actionSelf()    {        echo 'new action';    }}

In this case, when the user requestsselfThe output is triggerednew action.
Of course, you will find thatCActionClass, which is usedactionAnother method:

class SelfAction extends CAction{    public function run()    {        echo 'new action';    }}class PageController extends Controller{    public function actions()    {        return array(            'self' => 'application.controllers.actions.SelfAction',        );    }}

We recommend that you firstYIIFor a general understanding, read this document: Yii authoritative guide

When you create a single page, such as "About Us" and "Contact Us", you can write them all in actions.

Used to reuse actions

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.