在 Kohana 中,有没有办法输出当前实例化的所有模型的列表?
问问题
333 次
1 回答
1
不确定 Kohana,但可以在原生 PHP 中完成:
代码
$article = new Model_Article();
$declared_classes = get_declared_classes();
$target_parent_class = 'Model';
foreach($declared_classes as $class){
if(is_subclass_of($class,$target_parent_class))
echo "$class is a subclass of $target_parent_class <br/>";
}
输出
Kohana_ORM is a subclass of Model
ORM is a subclass of Model
Model_Article is a subclass of Model
如果您只想列出Model_Article
, 设置$target_parent_class = 'ORM';
于 2012-05-15T02:57:33.133 回答