Yii Framework Forum: Error 400 - Yii Framework Forum

Jump to content

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

Error 400 Your request is invalid Rate Topic: -----

#1 User is offline   skipper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-June 11

Posted 22 June 2011 - 10:57 PM

Hi,
I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out.
I have just written a simple code while I'm learning Yii.

I have a user controller which has an action that looks like this:
	public function actionGetUsername($userId)
	{
		$user = Users::model()->findByPK($userId);
		$username = $user->username;
		$this->render('index', array('username'=>$username));
	}

Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned username.
But when I go to the URL, sitename/user/getusername/1
I get error 400 - your request is invalid.

Plz let me know if I am missing something here.
0

#2 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 498
  • Joined: 21-May 11
  • Location:India

Posted 23 June 2011 - 12:37 AM

View Postskipper, on 22 June 2011 - 10:57 PM, said:

Hi,
I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out.
I have just written a simple code while I'm learning Yii.

I have a user controller which has an action that looks like this:
	public function actionGetUsername($userId)
	{
		$user = Users::model()->findByPK($userId);
		$username = $user->username;
		$this->render('index', array('username'=>$username));
	}

Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned username.
But when I go to the URL, sitename/user/getusername/1
I get error 400 - your request is invalid.

Plz let me know if I am missing something here.




Hi ,
You can try like ,

pass URL like : sitename/user/getusername&id=1

public function actionGetUsername()
	{
                $userId = $_REQUEST['id'];
		$user = Users::model()->findByPK($userId);
		$username = $user->username;
		$this->render('index', array('username'=>$username));
	}


it will work.
Thanks,
Kiran Sharma.
0

#3 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 498
  • Joined: 21-May 11
  • Location:India

Posted 23 June 2011 - 12:38 AM

Hi ,
You can try like ,

pass URL like : sitename/user/getusername&id=1

public function actionGetUsername()
	{
                $userId = $_REQUEST['id'];
		$user = Users::model()->findByPK($userId);
		$username = $user->username;
		$this->render('index', array('username'=>$username));
	}


it will work.
Thanks,
Kiran Sharma.
0

#4 User is offline   skipper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-June 11

Posted 23 June 2011 - 01:05 AM

Hi,
Thanks for that. But I would like the SEO friendly URLs to work.
There must be some workaround to this right?

I was also trying to write a function to display user info when the path has the username, like:
sitename/user/username
That is why I need to get that parameter value without using &username=somename

Do I have to do anything with the URL rules?
Plz let me know
0

#5 User is offline   phtamas 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 687
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 23 June 2011 - 10:28 AM

Parameter names in action methods must match the parameter names in the corresponding urlManager rule.
For
public function actionGetUsername($userId)


you should have something like
/<userId:\d+>


in the rule.

guide - action parameter binding
1

#6 User is offline   nguyendh 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 157
  • Joined: 21-March 11

Posted 23 June 2011 - 05:46 PM

View Postskipper, on 22 June 2011 - 10:57 PM, said:

Hi,
I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out.
I have just written a simple code while I'm learning Yii.

I have a user controller which has an action that looks like this:
	public function actionGetUsername($userId)
	{
		$user = Users::model()->findByPK($userId);
		$username = $user->username;
		$this->render('index', array('username'=>$username));
	}

Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned username.
But when I go to the URL, sitename/user/getusername/1
I get error 400 - your request is invalid.

Plz let me know if I am missing something here.


Did you add the getUsername to accessRules() in the controller ?

public function accessRules()
{
   return array(
            array('allow',
                      'actions=>array('index', 'view', 'getUsername'),
                      'users'=>array('*'),
            ..............
}


Also, have a look @ http://www.yiiframew...1/en/topics.url

It talks about URL management in Yii
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