CAutoComplete with database problems

I'm having some troubles trying to use cautocomplete with database as here:

http://www.yiiframew…31.html#msg8431

view

<?php $this->widget('CAutoComplete', array(


   'model'=>$cidade,


   'autoFill'=>True,


   'attribute'=>'estado_id',


   'minChars'=>2,


   'max'=>100,


   'url'=>'cidade/completeestados',


   'htmlOptions'=>array('size'=>'50'))); ?>

controller

    public function actionCompleteEstados() {


        if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))


        {


            $result=$this->getEstadosList($_GET['q']);


            echo implode("n",$result);


        }


    }





    protected function getEstadosList($search) {


        $search=strtolower($search);


        $connection=Yii::app()->db;


        $sql="SELECT nome FROM estados WHERE nome like lower('%' || :nome || '%')";


        $command=$connection->createCommand($sql);


        $command->bindParam(':nome', $search);


        $result=$command->query($sql);


        $results=$result->readAll();





        return $results;


    }

What i'm doing wrong ?

Second: YII_DEBUG are set to true, where to read the debug messages ?

my getEstadosList was wrong, here the new version. Now the problem is with readAll():

<?php


    protected function getEstadosList($search) {


        $search='%'.strtolower($search).'%';


        $connection=Yii::app()->db;


        $sql="SELECT nome FROM estados WHERE lower(nome) like :nome";


        $command=$connection->createCommand($sql);


        $command->bindParam(':nome',$search,PDO::PARAM_STR);


        $result=$command->queryAll($sql);


        $results=$result->readAll();





        return $results;


    }?>

I modified my code to not use the getEstadosList and implement everything in actionCompleteEstados. If i try to access the url without the Yii::app()->request->isAjaxRequest i get the right values, but with the Yii::app()->request->isAjaxRequest my CAutoComplete does not show the selected values.

<?php


    public function actionCompleteEstados() {


        if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))


        {


            $nome                = $_GET['q']; 


            $criteria            = new CDbCriteria;


            $criteria->select    = 'nome';


            $criteria->condition = 'lower(nome) LIKE :nome';


            $criteria->params    = array(':nome'=>"%$nome%");


            $criteria->limit     = 50;


            $estados             = Estado::model()->findAll($criteria);


            $result              = '';





            foreach($estados as $estado)


            {


                $result .= $estado->nome."n";


            }





            echo $result;


        }


    }


?>

Quote

What i'm doing wrong ?

Second: YII_DEBUG are set to true, where to read the debug messages ?

For log , you should use enable weblog route in order to view the debug messages on webpage. Here is an example



'components'=>array(


		'log'=>array(


			'class'=>'CLogRouter',


			'routes'=>array(


                array(


                    'class'=>'CWebLogRoute',//'CFileLogRoute',


                    'levels'=>'trace, info, error, warning',


                    'categories'=>'system.*',


                ),





      ),


),


Thanks for the tip @will.

About my problem with CAutoComplete, seems to be a wrong url parameter. I will check this later.

Can't get CAutoComplete to work. I have tried:

<?php $this->widget('CAutoComplete', array(


   'model'=>$cidade,


   'autoFill'=>True,


   'attribute'=>'estado_id',


   'minChars'=>2,


   'max'=>100,


   'url'=>'/cidade/completeestados', // with '/' at the beggining


   'htmlOptions'=>array('size'=>'50'))); ?>
<?php $this->widget('CAutoComplete', array(


   'model'=>$cidade,


   'autoFill'=>True,


   'attribute'=>'estado_id',


   'minChars'=>2,


   'max'=>100,


   'url'=>array('cidade/completeestados'), // usgin array


   'htmlOptions'=>array('size'=>'50'))); ?>


without success.

The actionCompleteEstados echo the results without problems when i access through the url without isAjaxRequest test.

Some help ?

Quote

Can't get CAutoComplete to work. I have tried:
<?php $this->widget('CAutoComplete', array(


   'model'=>$cidade,


   'autoFill'=>True,


   'attribute'=>'estado_id',


   'minChars'=>2,


   'max'=>100,


   'url'=>'/cidade/completeestados', // with '/' at the beggining


   'htmlOptions'=>array('size'=>'50'))); ?>
<?php $this->widget('CAutoComplete', array(


   'model'=>$cidade,


   'autoFill'=>True,


   'attribute'=>'estado_id',


   'minChars'=>2,


   'max'=>100,


   'url'=>array('cidade/completeestados'), // usgin array


   'htmlOptions'=>array('size'=>'50'))); ?>


without success.

The actionCompleteEstados echo the results without problems when i access through the url without isAjaxRequest test.

Some help ?

Did you try 'url'=>array('/cidade/completeestados') ?

Ty will.

array('/cidade/estadosautocomplete')

Solve the problem.

Now i’m doing the trick described here to search for one value and submit another. Something is going wrong, but i will find the solution.

Ty again for your help.