How to paste params into createUrl by jquery

Hi guys,

Have you ever paste params into


Yii::app()->createUrl()

But the params just can get by jquery.Because I have a dropdownlist and a link, when user click the Link, this will use createUrl to redirect user to spectificed controller, and pass params by get the dropdownlist value.

I’d tried like this:




echo CHtml::link(

                'Export',

                Yii::app()->createUrl('lichchay/exportexcel', array(

                    'id'=>'$("#cbo").val()'

                ))

            );



But it is not work

Any idea? Thanks :D

Your id here will be added to the url. So you will try to load an URL like (depending on the url management rules):




 /lichchay/exportexcel/id/$("#cbo").val()



Based on what you said, I think you should write a javascript function that will be called when the link is clicked. This function will construct the URL. Personnally, I would write something like this:





// Create the link with an id

echo CHtml::link('Export','#', array('id'=>'exportLink'));


// Create the url with a 1234 value as a placeholder

// You may have routes defined with id:\d+, that's why you should use an integer

$url = Yii::app()->createUrl('lichchay/exportexcel', array('id'=>1234));


// Replace the 1234 with the real id to use

Yii::app()->getClientScript()->registerScript("exportLinkScript", "

	$('#exportLink').click(function(){

		var id = $('#cbo').val();

		var url = '{$url}';

		window.location.href = url.replace('1234', id);

	});

");