Restfullyii + Yii-User

Trying to add Rest API, using restfullyii, with its own url rules

(yiiframework.com/forum/index.php/topic/33057-restfullyii-and-post-get-requests/)

Its working fine with posts, so i can get data via /api/posts or /api/posts/id links, but it doesnt work with users.

After installing restfullyii, to view admin user, for example, im having links like this

/index.php/user/user/view/id/1

and if im trying to get it going

/index.php/api/user (or /api/user/user/ or /api/user/view/ or /api/user/user/viev/ etc)

im getting 404 error with message Unable to resolve the request "user/REST.GET"

Any ideas?

Some examples to make it clear

UserController.php -> http://pastebin.com/fBA86Xx2

same code in

PostController.php -> http://pastebin.com/NUCN11iv works fine.

Here’s the restfullyii routes.php http://pastebin.com/UZdMcYJG

http://91.229.129.149/app/index.php/api/post - posts json (need to login to see items but its working)

http://91.229.129.149/app/index.php/api/user - thing just doesnt work

The difference between working post and NOT working user rest is that… I think its because of the urlManager.

http://91.229.129.149/app/index.php/post/view/1 - link on the #1 item in posts

http://91.229.129.149/app/index.php/user/user/view/id/1 - link on the #1 user (admin)

But still i dont know how to fix it and show restfullyii how to work with yii-user

Okay, after a week of trying i finally found a way. Had to email to the guy who actually made the extension.

He suggested to make my own custom controller just for this, so here’s the code:




<?php

Yii::import('application.modules.user.models.*');


class AppUserController extends Controller

{


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			 array('RestfullYii.filters.ERestFilter + REST.GET, REST.PUT, REST.POST, REST.DELETE'),

		);

	}


	public function actions()

	{

		return array(

			'REST.'=>'RestfullYii.actions.ERestActionProvider',

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow', 

				'actions'=>array('REST.GET', 'REST.PUT', 'REST.POST', 'REST.DELETE'),

				'users'=>array('*'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	public function restEvents()

	{

		$this->onRest('model.instance', function() {

    		return new User();

		});

	}

}



  1. Save as AppUserController.php

  2. Throw it into <app>/protected/controller/ folder

  3. Login into ur website, you can get All/Single user by doing requests:




Get all users / Get single user :

<app>/index.php/api/appUser/

<app>/index.php/api/appUser/1



Tried, it works! GLHF!

hi,

i’m new to yii …

i’m using your AppUserController to get the user details but how i post the data using restfullyii…if u have example code for contoller and model please provided to me…that’s help me …

Hi,

I am very new to Yii, using restFullYii extensions for CURD operations, i couldn’t use PUT and DELETE methods, but rest working good. I got error of

{"errorCode":500,"message":"The value for the column \"Id\" is not supplied when querying the table \"announcements\"."}

Please help me to fix this.