Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

[Yiibooster] [Select2]

$
0
0
Dear yii-collegues,
I have a form with yiibooster and a select2Row with person names (1 MB of data or 20000 records!). To avoid loading the complete data at the time of document loading (which took about 20 sec or so), I tried to load the data with the filter function of select2 via ajax (after user input):
  • form is loaded without data
  • when the user inputs some search term, the select2 widget shows only filtered records


So the action in PersonsController is:

protected function actionAllnames(){
	if(isset($_GET['q'])){
	    $queryterm  = $_GET['q'];
        $model      = new Persons;
        $persons    = Persons::model()->findAll(array(  'order'     => 'lastname', 
    	                                                'condition' => 'lastname LIKE :lastname', 
    	                                                'params'    => array(':lastname'=>$queryterm . '%')
                                                      ));
        // didn't work:
        // $data = array();
        // foreach ($persons as $person) {
        //      $data[] = array(
                            // 'id' => $person->uuid,
                            // 'text' => $person->lastname,
                            // );
        //}
        $data       = CHtml::listData($persons, 'uuid', 'lastname') ;
        echo CJSON::encode($data);
    }
	Yii::app()->end();
}


and in the view I have the select2Row:
...
<?php echo $form->select2Row($model,'person_uuid', array(   
       'asDropDownList' => false,
       'options' => array(
                       'minimumInputLength'=>'2',
                       'width'      => '348px',
                       'placeholder'=> 'Select Person',
                       'allowClear' => TRUE,
                       'ajax'       => array(
                                   'url'       => Yii::app()->controller->createUrl('persons/allnames'),
                                   'dataType'  => 'json',
                                   'data'      => 'js:function(term, page) { return {q: term }; }',
                                   'results'   => 'js:function(data) { return {results: data}; }',
                               ),
                        ),
        'id' =>'fld-personselect',
        )) ; 
 ?>
...


After input of 2 characters, for example "Te", there are no values shown, only "Searching..."

In firebug the following is shown: 500 Internal Server Error
Parameters
q Te
r persons/allnames

and there is this error :

<h1>CException</h1>
<p>PersonsController and its behaviors do not have a method or closure named "actionallnames". 
(... CInlineAction.php(49): CComponent->__call('actionallnames', Array)
...


But action is named "actionAllnames" in PersonsController and the action is also allowed:

array('allow', // allow authenticated user to perform 'create' and 'update' actions
        'actions'=>array('create','update','edit','allnames'),
		'users'=>array('@'),
    ),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
		'actions'=>array('admin','delete','allnames'),
		'users'=>array('admin'),
 ... 


Maybe I'm missing something on the ajax/js side, should there be an extra
javascript? :blink: Any ideas are very wellcome ... thank you in advance!
Greetings

Viewing all articles
Browse latest Browse all 18717

Trending Articles