0

I have a url pattern defined as below for a REST API build using yii.

      'urlManager'=>array(
      'urlFormat'=>'path',
      'rules'=>array(
                      array('api/default/list', 'pattern'=>'api/<model:\w+>', 'verb'=>'GET'),
                      array('api/default/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
                      array('api/default/update', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'PUT'),
                      array('api/default/delete', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'DELETE'),
                      array('api/default/create', 'pattern'=>'api/<model:\w+>', 'verb'=>'POST'),
      '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
      ),
      ),

What i am trying now is,

http://example.com/RestApi/index.php/api/post?offset=5&limit=10

The above works, but the following doesnt work.

http://example.com/RestApi/index.php/api/post/offset/5/limit/10

How can i make it work like second way? what changes needs to be done to the Url Manager ?

Thanks

Update

The error i get for second way is,

Unable to resolve the request "api/post/offset/5/limit/10".

2
  • Did you set up your .htaccess file Commented Nov 21, 2013 at 5:38
  • @crafter nope. i didnt. Commented Nov 21, 2013 at 5:42

1 Answer 1

1

You can try this:

 'urlManager'=>array(
      'urlFormat'=>'path',
      'rules'=>array(
                      array('api/default/view', 'pattern'=>'api/<model:\w+>/<id:\d+>/*', 'verb'=>'GET'),

                      array('api/default/list', 'pattern'=>'api/<model:\w+>/*', 'verb'=>'GET'),

            .............
      ),
  ),

I moved api/default/view rule to avoid overwriting another rules.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but it doesnt trigger the way i need, for example, url 1 - localhost/RestApi/index.php/api/user | url 2 localhost/RestApi/index.php/api/user/1 . url 1 works with any number of addition parameters but url 2 doesnt work at all because firs change overrides the url 2 pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.