Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. public function actionAutocomplete() {
  2.         //echo "<script>alert('test');</script>";
  3.         $results = Array();
  4.         $model = Yii::app()->db->quoteValue($_GET['modelName']);
  5.         $parentId = (int) $_GET['parentId'];
  6.         $parentFieldName = Yii::app()->db->quoteColumnName($_GET['parentFieldName']);
  7.  
  8.         if (isset($_GET['term'])) {
  9.             $search = Yii::app()->db->quoteValue($_GET['term']);
  10.             foreach ($model::model()->findAll(array(
  11.                 'condition' => "$parentFieldName = '$parentId' AND name like '%$search%'",
  12.                 'order' => 'name')) as $child) {
  13.                 $results[] = array('label' => $child->name, // value for input field
  14.                     'id' => $child->id, // return value from autocomplete
  15.                 );
  16.             }
  17.             echo CJSON::encode($results);
  18.             Yii::app()->end();
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement