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 difference does he have with these methods, such as Actionindex? What I saw in Yii's video tutorial was to do the verification code.

Reply content:

What difference does he have with these methods, such as Actionindex? What I saw in Yii's video tutorial was to do the verification code.

For example, define an action with a file, rather than define it in a controller

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

For example:
Official example: in the 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'),                        ),                           );    }

You can access the verification code directly through the Xxx?r=site/captcha!

Common operations, Acontroller and Bcontroller have an edit method that you can put into actions

Thanks for inviting! :)
As the name implies, there action is no doubt is used to describe the controller's actions, generally, that is actionIndex , the default action.
Example:

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

The default action, output, is triggered when the user requests it default action .
Of course you can also define specific action , for example:

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

At this point, the output is triggered when the user requests an self action new action .
Of course you'll find CAction another class, which is the other way to use it action :

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

The proposed master before the formal development, the first to YII have a general understanding, you can read this document: "Yii authoritative guide"

When you want to make a single page, such as "About Us", "Contact Us", can be written in the actions.

Used to re-use the action.

  • Related Article

    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.