Url Rule Pattern

Can anyone please post Url rule pattern example




public function parseRequest($manager, $request)

    {

        $pathInfo = $request->getPathInfo();

        if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) {

            // check $matches[1] and $matches[3] to see

            // if they match a manufacturer and a model in the database

            // If so, set $params['manufacturer'] and/or $params['model']

            // and return ['car/index', $params]

        }

        return false;  // this rule does not apply

    }



I dont know preg_match and need help with


'%^(\w+)(/(\w+))?$%

this part…

Function create url is set to create category/$row[‘url’] and i need to create parseRequest for this…

Is this related to gridview action column?

The default regexp for default action column url is generated based on the model class name. (generally folks keep the base part of controller and model naming similar when generating CRUD - so this tends to work by default). You can override this with whatever you need using the urlCreator property in ActionColumn.

But I think your query is not exactly related to this? Can you confirm?

Thank you for the replay, actually i am using




 'urlManager' => [

            'class' => 'yii\web\UrlManager',

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => [

               ['class' => 'app\components\CategoryUrlRule', 'connectionID' => 'db'],

            ],



And it looks like this:





class CategoryUrlRule extends UrlRule

{


    public $connectionID = 'db';


    public function createUrl($manager, $route, $params)

    {

        if ($route === 'category/view') {

            if (isset($params['id'])) {


               /** Find $row with that id and get category url ... */


                return 'category' . '/' . $row['url'];

            }

        }

        return false; // this rule does not apply

    }




    public function parseRequest($manager, $request)

    {

        $pathInfo = $request->getPathInfo();

        if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) {

        

           /** MISSING CODE + BAD PATTERN **/




            // check $matches[1] and $matches[3] to see

            // if they match a manufacturer and a model in the database

            // If so, set $params['manufacturer'] and/or $params['model']

            // and return ['car/index', $params]

        }

        return false;  // this rule does not apply

    }


} 






And i don’t know how to write pattern for parsing request… I need just a simple example :)