[right]سلام
من 2تا جدول به صورت زیر دارم :
contact( id, name , tel ,…, sid){ sid foriegnkey}
user('sid, name , …){sid primary key}
من میخوام از
autocomplete
در یک فرم جستجو استفاده کنم. زمانیکه کاربر نامی را وارد میکند
suggestion
عمل کند.
به این صورت که نام را در هر 2 جدول بگردد.
اما
در کد زیر
join
را نمیپذیرد
[/right]
public function actionAutoCompleteLookup()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
{
/* q is the default GET variable name that is used by
/ the autocomplete widget to pass in user input
*/
$name = $_GET['q'];
// this was set with the "max" attribute of the CAutoComplete widget
$limit = min($_GET['limit'], 50);
//$n=$_GET['name'];
$criteria = new CDbCriteria;
$criteria->condition = '(name LIKE :sterm or t1.name LIKE :sterm)and sid=:s';
$criteria->params = array(":sterm"=>"%$name%" ,':s'=>yii::app()->session['sid']);
$criteria->limit = $limit;
echo $criteria;
$userArray = Contact::model()->with('s')->findAll($criteria);
$returnVal = '';
foreach($userArray as $userAccount)
{
$returnVal .= $userAccount->getAttribute('name').'|'
.$userAccount->getAttribute('idcontact')."\n";
}
echo $returnVal;
}
}
[right]با تشکر[/right]