Hello. There is a url of type /index.php?r=post/view&id=1&title=abcd. Need to do the following url: / post / abcd.

In the rules urlManager expose:

'post/<title:.*?>'=>'items/view', 

The result is: / post / abcd? Id = 1

Is it even possible to remove the id from the url. Is there yes, how?

Thank.

    1 answer 1

    Searching an article for a title is not a good idea, I would advise adding the "uri" field to a table with posts with unique values ​​that would store the title of the article name in the transcription with replaced hyphens and spaces of characters

    In the rules:

     'post/<uri>' => 'item/view' 

    In the top:

     $this->createUrl('item/view',array('uri'=>$model->uri)) 

    In the action:

     $model = Post::model()->find('uri = :uri', [':uri' => $uri]); 

    This way you will get the url / post / hello-world for an article titled "Hollo world !!!"

    P.S. I can cheat, at once I apologize, for a long time I haven’t been Kolupa in Yii, I was busy with Yii2