(SOLVED) Retreiving table names with CDbSchema

Hi!

I’m pretty new to Yii and also PHP OOP, so maybe I am missing some central concepts.

I am trying to populate an array with all table names in my database and then putting them in a menu.

I am doing this inside the layouts/main.php file. I tried using the following code:




$tables = CDbSchema::getTableNames();


foreach ($tables as $table)

{

    $table_list[] = array("url"=>array("route"=>"$item/admin"),

                                      "label"=>"$item",

                        );

}



When I try to access any page I get something like the following error:




CException

Description


Property "CourseController._tableNames" is not defined.



I believe I am calling the getTableNames method in the wrong way or maybe from the wrong place. Would be grateful for any help and best practice tips for this kind of situation.

Thanks!

I think CDbSchema::getTableNames() is not a static method, so you can’t call it like that. Indeed, you can use:




Yii::app()->db->schema->tableNames



The tableNames property returns an array of table names ;D

Thanks! Exactly what I was looking for!