Routing problems caused by action case combination in YII2 controller

Source: Internet
Author: User

YII1, if the following controller is present

class extends Ccontroller {    publicfunction  actiongetmobilephone () {        //  Some code ...     }}

Then, by accessing Http://your-domain-name/bind/getMobilePhone, you can access the

If the above code is accessed in Yii2, it needs to be accessed http://your-domain-name/bind/get-mobile-phone this way, because the CreateAction method is rewritten in Yii2

The createaction in YII1

     Public functionCreateAction ($actionID)    {        if($actionID= = = "")            $actionID=$this-DefaultAction; if(method_exists($this, ' action '.$actionID) &&strcasecmp($actionID, ' s '))//we have the actions method            return NewCinlineaction ($this,$actionID); Else        {            $action=$this->createactionfrommap ($this->actions (),$actionID,$actionID); if($action!==NULL&&!method_exists($action, ' Run '))                Throw NewCException (yii::t (' Yii ', ' Action class {class} must implement the ' run ' method.Array(' {class} ' = =Get_class($action)))); return $action; }    }

The createaction in Yii2

     Public functionCreateAction ($id)    {        if($id= = = "") {            $id=$this-DefaultAction; }        $actionMap=$this-actions (); if(isset($actionMap[$id])) {            returnYii::createobject ($actionMap[$id], [$id,$this]); } ElseIf(Preg_match('/^[a-z0-9\\-_]+$/',$id) &&Strpos($id, '--') = = =false&&Trim($id, '-') = = =$id) { //Here is the format for judging $id that is the method name $methodName= ' action '.Str_replace(‘ ‘, ‘‘,Ucwords(implode(‘ ‘,Explode(‘-‘,$id)))); //This is the name of the reorganization method if(method_exists($this,$methodName)) {                $method=New\reflectionmethod ($this,$methodName); if($method->ispublic () &&$method->getname () = = =$methodName) {                    return NewInlineaction ($id,$this,$methodName); }            }        }        return NULL; }

The red annotation is the difference between YII1 and YII2 in the combination of method names, YII1 is simply a combination.

Routing problems caused by action case combination in YII2 controller

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.