kohana专栏自省 [英] kohana columns introspection
问题描述
我想知道KOHANA模型上$ _table_columns数组的功能是什么.
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?
推荐答案
$_table_columns
反映了您的表列结构.因此,如果您的表有3列(id,name,desc),则将$_table_columns
设置为array('id' => '', 'name' => '', 'desc' => '')
.
$_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' => '')
.
默认情况下,$_table_columns
是一个空数组.当使用类扩展ORM且不覆盖$_table_columns
时,ORM将通过调用SHOW FULL COLUMNS FROM table_name
命令自动将其填充.如果要避免此额外的数据库调用,可以自行初始化$_table_columns
:
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' => '');
}
在此处中查看有关详情.
这篇关于kohana专栏自省的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!