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;
}
}
?>