Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionAutocomplete() {
- //echo "<script>alert('test');</script>";
- $results = Array();
- $model = Yii::app()->db->quoteValue($_GET['modelName']);
- $parentId = (int) $_GET['parentId'];
- $parentFieldName = Yii::app()->db->quoteColumnName($_GET['parentFieldName']);
- if (isset($_GET['term'])) {
- $search = Yii::app()->db->quoteValue($_GET['term']);
- foreach ($model::model()->findAll(array(
- 'condition' => "$parentFieldName = '$parentId' AND name like '%$search%'",
- 'order' => 'name')) as $child) {
- $results[] = array('label' => $child->name, // value for input field
- 'id' => $child->id, // return value from autocomplete
- );
- }
- echo CJSON::encode($results);
- Yii::app()->end();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement