Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Autocomplete, Convert Space(%) To + In Link

$
0
0
Hiii

I have an autocomplete script which search for merchants in my system, and sends the user to a new page..

View:
<?php $this->widget('ext.myAutoComplete', array(
    	'name' => 'merchantName',
    	'source' => $this->createUrl('review/autocomplete'),
    	'options' => array(
        	'minLength'=>1,
        	'autoFill'=>false,
        	'focus'=> 'js:function( event, ui ) {
	            	$( "#autocomplete" ).val( ui.item.name );
    	        	return false;
        	}',
		'select' => 'js:function( event, ui ){
     			top.location = "write/" + ui.item.name;
		}'
     	),
    	'htmlOptions'=>array('class'=>'input-1', 'autocomplete'=>'off', 'size'=>80,),
    	'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
	        return $( "<li></li>" )
	        .data( "item.autocomplete", item )
	        .append( "<a>" + item.name +  "</a>" )
	        .appendTo( ul );
    	};'
)); ?>


Controller:
public function actionAutocomplete(){
    	$res = array();
    	$term = Yii::app()->getRequest()->getParam('term', false);
    	if ($term)
    	{
     	 	$sql = 'SELECT id, name FROM merchants where LCASE(name) LIKE :name';
      		$cmd = Yii::app()->db->createCommand($sql);
      		$cmd->bindValue(":name","%".strtolower($term)."%", PDO::PARAM_STR);
      		$res = $cmd->queryAll();
    	}
    	echo CJSON::encode($res);
    	Yii::app()->end();
	}


This works all fine.. But what happens when i pick a merchant named, etc. "Merchant Casper"..
It sends me to: "Write/Merchant%Casper"

But I would like all the % to be switched out with + instead..

How can i do this??


// Casper

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>