Yii Framework Forum: How To Pass Another Parameter In Restful Api ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Pass Another Parameter In Restful Api ? Rate Topic: -----

#1 User is offline   DC Alliances 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-September 13

Posted 23 September 2013 - 02:14 PM

Hi there

We are quite new to Yii Framework and the reason we go this framework that we can utilise this webservice - from RESTFul API - http://www.yiiframew...on/restfullyii/

We have this action defined on our Ad controller:

public function actionListByCategory($id)
	{
		//$dataProvider=new CActiveDataProvider(ad::model()->with('subcategory'));
		//$this->render('index',array(
		//	'dataProvider'=>$dataProvider,
		//));
		
		$dataProvider=new CActiveDataProvider('ad',array(
                'criteria'=>array(
                    'order'=>'adid desc',
                    'condition'=>'subcatid = '.$id,
                ),
				'pagination'=>array(
                        'pageSize'=>10,
                        //'route'=>'user/login/login',
                ),
        ));
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
		
		
	}



But then how do execute this on the url on the browser with this /api/ extenstion in http://localhost:888...stbycategory/21 ?

We've tried http://localhost:888...stbycategory/21 and it doesnt' seem to work and we have this message: {"success":false,"message":"Resource Not Found","data":{"errorCode":404,"message":"Resource Not Found"}}

I believe this will be something in relation to routes maybe ?

Here's the routes at Starship.Restfullyii extension - C:\wamp\www\dev-ph-com\webservice-dev-restful\protected\extensions\starship\RestfullYii\config

<?php
return [
	'api/<controller:\w+>'=>['<controller>/REST.GET', 'verb'=>'GET'],
	'api/<controller:\w+>/<id:\w*>'=>['<controller>/REST.GET', 'verb'=>'GET'],
	'api/<controller:\w+>/<id:\w*>/<param1:\w*>'=>['<controller>/REST.GET', 'verb'=>'GET'],
	'api/<controller:\w+>/<id:\w*>/<param1:\w*>/<param2:\w*>'=>['<controller>/REST.GET', 'verb'=>'GET'],

	['<controller>/REST.PUT', 'pattern'=>'api/<controller:\w+>/<id:\w*>', 'verb'=>'PUT'],
	['<controller>/REST.PUT', 'pattern'=>'api/<controller:\w+>/<id:\w*>/<param1:\w*>', 'verb'=>'PUT'],
	['<controller>/REST.PUT', 'pattern'=>'api/<controller:\w*>/<id:\w*>/<param1:\w*>/<param2:\w*>', 'verb'=>'PUT'],	

	['<controller>/REST.DELETE', 'pattern'=>'api/<controller:\w+>/<id:\w*>', 'verb'=>'DELETE'],
	['<controller>/REST.DELETE', 'pattern'=>'api/<controller:\w+>/<id:\w*>/<param1:\w*>', 'verb'=>'DELETE'],
	['<controller>/REST.DELETE', 'pattern'=>'api/<controller:\w+>/<id:\w*>/<param1:\w*>/<param2:\w*>', 'verb'=>'DELETE'],

	['<controller>/REST.POST', 'pattern'=>'api/<controller:\w+>', 'verb'=>'POST'],
	['<controller>/REST.POST', 'pattern'=>'api/<controller:\w+>/<id:\w+>', 'verb'=>'POST'],
	['<controller>/REST.POST', 'pattern'=>'api/<controller:\w+>/<id:\w*>/<param1:\w*>', 'verb'=>'POST'],
	['<controller>/REST.POST', 'pattern'=>'api/<controller:\w+>/<id:\w*>/<param1:\w*>/<param2:\w*>', 'verb'=>'POST'],

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



I'm appreciated your feedback.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users