PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Yii UrlManager not working

 March 08, 2022     php, url, url-routing, yii     No comments   

Issue

I am having Yii UrlManager issue.

I want to have following url: localhost/mylist/this-is-demo-content

It is working fine by:

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                '<controller:\w+>/<title:\w-]+>' => '<controller>/view',
                '<controller:\w+>/<id1:\w+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            ),

But when I try localhost/mylist/this, it says

no action found "this"

Here mylist is controller and I have one action

public function actionView($title)
{
    echo $title;
}

I have also tried this url pattern:

'<controller:\w+>/<title:[A-Z a-z 0-9 _ -]+>' => '<controller>/view',

but could not work


Solution

Continue from these simplified rules:

    'rules'=>array(
        // Place custom rules here
        'mylist/<title>' => 'mylist/view',

        // Nothing should go below these default rules
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
    ),


Answered By - Samuel Liew
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing