Home  >  Article  >  Backend Development  >  PHP development framework Yii Framework tutorial (34) Zii component-AutoComplete example

PHP development framework Yii Framework tutorial (34) Zii component-AutoComplete example

黄舟
黄舟Original
2017-01-22 09:52:271883browse

CJuiAutoComplete can automatically prompt the user to input text based on the first few characters entered by the user when typing. It encapsulates the JUI autocomplete plugin.

The basic usage is as follows

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'city',
'source'=>$data,
// additional javascript options for the autocomplete plugin
'options'=>array(
'minLength'=>'2',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>

The automatically prompted data source is completed by configuring the source attribute. In actual application, it can be read from databases, files, etc. For simplicity, this example uses an array defined in SiteController.

public function actionIndex()
{
$data=array('Nanjing', 'Beijing', 'Perth',
'Chicago','Paris','Pengnai','Sydney');
$this->render('index', array(
'data' => $data,
));
}

PHP development framework Yii Framework tutorial (34) Zii component-AutoComplete example

The above is the content of the PHP development framework Yii Framework tutorial (34) Zii component-AutoComplete example. For more related content, please pay attention to the PHP Chinese website (www.php.cn )!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn