Php yii cgui从dervied列自动完成

Php yii cgui从dervied列自动完成,php,yii,autocomplete,Php,Yii,Autocomplete,我想在文本框中使用名称自动完成。但是,名称被拆分为多个列,first\u name,last\u name。我有以下代码 查看 $this->widget('zii.widgets.jui.CJuiAutoComplete',array( 'attribute'=>'CONSULTANT', 'model'=>$invoices, 'sourceUrl'=>array('SugarContacts/

我想在文本框中使用名称自动完成。但是,名称被拆分为多个列,
first\u name
last\u name
。我有以下代码

查看

$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
            'attribute'=>'CONSULTANT',
            'model'=>$invoices,

            'sourceUrl'=>array('SugarContacts/InvoicesNameList'),
            // additional javascript options for the autocomplete plugin
            'options'=>array(
                    'minLength'=>'2',
                    'select'=>"js:function(event, ui) { $('#Invoices_CONSULTANT').val(ui.item.id); getAddress(ui.item.id,'billing');}  "
            ),
            'htmlOptions'=>array(
                    'style'=>'height:20px;',
                    'id'=>"Invoices_CONSULTANT_search",
                    "size"=>"50",
                    'name'=>"Invoices[CONSULTANT]",
            ),
        ));
ccontroller

公共职能行动() { 返回数组(

}

型号

public function getName(){
        return $this->first_name . " " . $this->last_name;
    }

我不得不修改
eautocomplete
action类

 public function run()
    {
        if(isset($this->model) && isset($this->attribute)) {
            $criteria = new CDbCriteria();
            $criteria->compare($this->attribute, $_GET['term'], true);
            if ($this->model == "SugarContacts") {
                if($this->attribute == "name"){ //used on invoices
                    $criteria->select = "*, CONCAT(t.first_name, ' ', t.last_name) AS name";
                    $criteria->condition = "(CONCAT(t.first_name, ' ' , t.last_name) LIKE :ycp0 || accounts.name LIKE :ycp0) and length(t.id)<8"; //use id length to grab nav contacts
                    $criteria->join = " join sugarcrm6.accounts_contacts on t.id = sugarcrm6.accounts_contacts.contact_id" .
                     " join sugarcrm6.accounts on sugarcrm6.accounts_contacts.account_id = sugarcrm6.accounts.id"; // join tables to include company name in search
                }
                else
                    $criteria->addSearchCondition('last_name', $_GET['term'], true,"OR");


            }
            $model = new $this->model;
           // print_r($model);
           // print_r($criteria);
            //exit();
            foreach($model->findAll($criteria) as $m)
            {
                if ($this->model == "SugarContacts") {
                    if($this->attribute == "name"){ //used on invoices
                        $this->results[] = array(
                                //'label'=>trim($m->{$this->attribute}),
                                'value'=>trim($m->{$this->attribute}) . " " . " : " . trim($m->sugarAccountsContacts1->sugarAccounts->billing_address_street),
                                'id'=>$m->primaryKey
                        );

                    }else{
                        $this->results[] = array(
                                //'label'=>trim($m->{$this->attribute}),                            
                                'value'=>trim($m->{$this->attribute}) . " " . trim($m->last_name) . " : " . trim($m->primary_address_street), 
                                'id'=>$m->primaryKey 
                                );
                    }
                }else{
                    $this->results[] =  array(
                            'value'=>trim($m->{$this->attribute}), 
                            'id'=>$m->primaryKey 
                            ); 
                }

            }

        }


       if ($this->model != "SugarContacts" && !is_a($model,"Bids")) {
            $this->results = array_unique($this->results);
       }


        echo CJSON::encode($this->results);
    }
公共函数运行()
{
if(isset($this->model)&&isset($this->attribute)){
$criteria=新的CDbCriteria();
$criteria->compare($this->attribute,$\u GET['term'],true);
如果($this->model==“SugarContacts”){
如果($this->attribute==“name”){//用于发票
$criteria->select=“*,CONCAT(t.first\u name,”,t.last\u name)作为名称”;
$criteria->condition=“(CONCAT(t.first_name)”,t.last_name)如:ycp0 | | accounts.name如:ycp0)和长度(t.id)
 public function run()
    {
        if(isset($this->model) && isset($this->attribute)) {
            $criteria = new CDbCriteria();
            $criteria->compare($this->attribute, $_GET['term'], true);
            if ($this->model == "SugarContacts") {
                if($this->attribute == "name"){ //used on invoices
                    $criteria->select = "*, CONCAT(t.first_name, ' ', t.last_name) AS name";
                    $criteria->condition = "(CONCAT(t.first_name, ' ' , t.last_name) LIKE :ycp0 || accounts.name LIKE :ycp0) and length(t.id)<8"; //use id length to grab nav contacts
                    $criteria->join = " join sugarcrm6.accounts_contacts on t.id = sugarcrm6.accounts_contacts.contact_id" .
                     " join sugarcrm6.accounts on sugarcrm6.accounts_contacts.account_id = sugarcrm6.accounts.id"; // join tables to include company name in search
                }
                else
                    $criteria->addSearchCondition('last_name', $_GET['term'], true,"OR");


            }
            $model = new $this->model;
           // print_r($model);
           // print_r($criteria);
            //exit();
            foreach($model->findAll($criteria) as $m)
            {
                if ($this->model == "SugarContacts") {
                    if($this->attribute == "name"){ //used on invoices
                        $this->results[] = array(
                                //'label'=>trim($m->{$this->attribute}),
                                'value'=>trim($m->{$this->attribute}) . " " . " : " . trim($m->sugarAccountsContacts1->sugarAccounts->billing_address_street),
                                'id'=>$m->primaryKey
                        );

                    }else{
                        $this->results[] = array(
                                //'label'=>trim($m->{$this->attribute}),                            
                                'value'=>trim($m->{$this->attribute}) . " " . trim($m->last_name) . " : " . trim($m->primary_address_street), 
                                'id'=>$m->primaryKey 
                                );
                    }
                }else{
                    $this->results[] =  array(
                            'value'=>trim($m->{$this->attribute}), 
                            'id'=>$m->primaryKey 
                            ); 
                }

            }

        }


       if ($this->model != "SugarContacts" && !is_a($model,"Bids")) {
            $this->results = array_unique($this->results);
       }


        echo CJSON::encode($this->results);
    }