Yii Framework Forum: Cjuiautocomplete On Url With Id Parameter - Yii Framework Forum

Jump to content

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

Cjuiautocomplete On Url With Id Parameter Rate Topic: -----

#1 User is offline   _Stan_ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 18-January 13

Posted 18 January 2013 - 02:16 PM

I need to implement DB lookup field and am trying to make use of CJuiAutoComplete widget. I need the widget to fetch data from the following URL: www/controller/action/ID/?term=<query>. That is I need the request to come to an action handler similar to actionView, which accepts a numerical paramater ID (if it could be a string, it would be better, but I decided to start from a simplified implementation).

When I define CJuiAutoComplete in my form as the following:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'source' => $this->createUrl('price/lookup/1'),...


I've got an error "Invalid request" in logs, with the following URL (www/price/lookup/1?term=xxx), which is correct in the sense that I want it to be like this. But Yii does not apparently like it.

If I change the form to have:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'source' => $this->createUrl('price/lookup'),...


the request is handled normally by Yii (URL is www/price/lookup?term=xxx), but I do not receive the ID which I need to pass.

The question is how to setup Yii in order to accept the required URL for autocompletion? I think this is somehow related to the main configuration file, and specifically urlManager's rules, but I don't know what to write there to fix the problem. Currently I have standard configuration:

		'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName' => false,
			'rules'=>array(
			  'site/page/<view:\w+>' => 'site/page',
				'<controller:\w+>/<id:\d+>'=>'<controller>/view',
				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
			),
		),


URLs with controller/action/id are accepted. Also I do not see here any special case for URLs with "?param=value" part in the line where controller/action rule is defined, nevertheless it accepts "?param=value" in the case when I don't provide the ID.

Could someone shed some light on this?
0

#2 User is offline   _Stan_ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 18-January 13

Posted 18 January 2013 - 03:26 PM

I found what's the origin of the problem. The error was that the name of the action parameter was other than $id. Yii resolves params by name using reflection.
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