Skip to content

Commit

Permalink
proper action for autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomba committed Aug 17, 2012
1 parent 2686ca3 commit c980ff5
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions framework/gii/generators/model/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,15 @@ class ModelGenerator extends CCodeGenerator
* @param string $q the user entered term for filtering tablenames
* @return string the json array of tablenames that contains the entered term $q
*/
public function actionGetTableNames($db, $q)
public function actionGetTableNames($db)
{
if(Yii::app()->getRequest()->getIsAjaxRequest())
{
if(empty($db) || Yii::app()->hasComponent($db)===false || !(Yii::app()->getComponent($db) instanceof CDbConnection))
throw new CHttpException(404,'The database component is not valid.');
$all = array();
if(!empty($db) && Yii::app()->hasComponent($db)!==false && (Yii::app()->getComponent($db) instanceof CDbConnection))
$all=array_keys(Yii::app()->{$db}->schema->getTables());

$model=$this->prepare();
$all=array_keys(Yii::app()->{$db}->schema->getTables());

if($q!=='')
{
$filtered=array();
foreach($all as $table)
{
if(stripos($table, $q) !== false)
$filtered[]=$table;
}
echo json_encode($filtered);
}
else
echo json_encode($all);
echo json_encode($all);
}
else
throw new CHttpException(404,'The requested page does not exist.');
Expand Down

0 comments on commit c980ff5

Please sign in to comment.