Yii Framework Forum: Restfullyii + Yii-User - Yii Framework Forum

Jump to content

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

Restfullyii + Yii-User troubles Rate Topic: -----

#1 User is offline   Topper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 13

Posted 24 November 2013 - 12:01 PM

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?
0

#2 User is offline   Topper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 13

Posted 25 November 2013 - 08:30 AM

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.14...ex.php/api/post - posts json (need to login to see items but its working)
http://91.229.129.14...ex.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.14...php/post/view/1 - link on the #1 item in posts
http://91.229.129.14.../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
0

#3 User is offline   Topper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 23-November 13

Posted 30 November 2013 - 04:13 PM

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!
0

#4 User is offline   MohammedNizamudeen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 23-November 13

Posted 14 March 2014 - 07:05 AM

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 ...
0

#5 User is offline   souber sathick 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-April 14

Posted 30 April 2014 - 08:46 AM

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.
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