1
votes

I'm a newbie of Yii and now I have a link:

localhost/qr/delete/33

I dont' know how to make it as

localhost/qr-code/delete/33

using urlManager in main.php.

2
inside localhost qr is your application folder? please try this and paste in in main.php 'qr-code/delete/<id:\d+>'=>'qr/delete/id/', - Jason W
yes, qr is my application folder. And I have tried use 'qr-code/<action:\w+>/<id:\d+>'=>'qr/<action>/<id>' but it not worked. - user2978324
Wait qr is a folder name? Not the name of your controller? What controller are you trying to use the delete function on? - Pitchinnate
what error your are getting and please tell the folder + controller + action and try the one pasted above - Jason W
I put qr folder in themes\views\qr and the themes folder is out of protected folcer. My controller is QrController to handle actionDelete(), actionEdit(). And I have error 404 requested page not found. Please help me - user2978324

2 Answers

1
votes

Should be able to add this to your array in your config:

'qr-code/<action:\w+>/<id:\d+>' => 'qr/<action>',
//other rules here

This will make it so that delete or update actions can work. Make sure you put this before other rules so that it has a higher priority. id will be passed as a variable to your action in your qr controller

public function actionDelete($id) {
    //your code here
}
0
votes

If qr is controller , delete is action and 33 is id, then here is your solution .

   rules = array(
      '<controller:(qr)>-code/delete/<id:\d+>'=>'<controller>/delete',

      '<controller:\w+>/<id:\d+>' => '<controller>/view',
      '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
      '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
   ),