问题
I would like to know which is the functionality of the $_table_columns array on a KOHANA model.
I ask this since the table's columns are loaded by introspection, what is the use of this array, is it for default values to the properties?
回答1:
$_table_columns
reflects your table column structure. So if your table has 3 columns (id, name, desc), $_table_columns
will be setup to array('id' => '', 'name' => '', 'desc' => '')
.
By default $_table_columns
is an empty array. When you extend ORM with your class and don't override $_table_columns
, it will be automatically filled by ORM by calling SHOW FULL COLUMNS FROM table_name
command. If you want to avoid this additional DB call, you can initialize $_table_columns
on your own:
class Model_User extends ORM {
protected $_table_columns = array('id' => '', 'name' => '', 'desc' => '');
}
Check here for more details.
来源:https://stackoverflow.com/questions/8017337/kohana-columns-introspection