What does this code do?

I just started at a new company that has a semi-developed Yii app. The following snippets of code are for an auto-complete form. The ‘value’ section crashes the app. I commented out the line, and everything seems to work.

What does the ‘value’ do, what is it for, and what do you guys think the person before me wanted to do with this line?

Thanks!


$this->widget('CAutoComplete',

          array(

                         //name of the html field that will be generated

             'name'=>'company_name',

                         //replace controller/action with real ids

             'url'=>array('contact/CompanyAutoCompleteLookup'),

             'max'=>10, //specifies the max number of items to display

             //'value'=>Company::model()->findByPK($model->id)->name,

                         //specifies the number of chars that must be entered

                         //before autocomplete initiates a lookup

             'minChars'=>2,

             'delay'=>500, //number of milliseconds before lookup occurs

             'matchCase'=>false, //match case when performing a lookup?


                         //any additional html attributes that go inside of

                         //the input field can be defined here

             'htmlOptions'=>array('size'=>'40'),


             'methodChain'=>".result(function(event,item){\$(\"#Contact_company_id\").val(item[1]);})",

             ));

Lookup the initial value for the input field of the widget.

You will need to have an instance of Company (named $model) defined in the view.

Also read about AR in the guide

/Tommy

Ahhh, thanks. With that info, I’m guessing the other guy didn’t check if the value was set. The form is used for creating new contacts and editing existing ones. Makes sense now. Thanks again.

It seems like they should have set the model and attribute variables instead of name and value.