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.yiiframework.com/extension/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:8888/dev-ph-com/webservice-dev-restful/index.php/ad/listbycategory/21 ?
We’ve tried http://localhost:8888/dev-ph-com/webservice-dev-restful/index.php/api/ad/listbycategory/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.