【发布时间】:2012-03-08 17:08:28
【问题描述】:
我想使用 Kohana 3 具有的默认 ORM 从我的数据库中获取一些行,但我没有得到我想要的 :-)
In my Controller:
$comptes = ORM::factory('compte');
#$comptes->where('empresa_id', '=', 2)->find_all();
$comptes->find_all();
此查询在我的 SQL 中返回 169411 行,但这里没有返回任何内容。当然,我可以使用 where、limit 或其他方式进行限制,但我正在尝试使用 Kohana 的基础知识。
This returns 1
$result = count($comptes);
In my model view:
<?php var_dump($comptes)?>
produces this:
object(Model_Compte)#16 (34) { ["_has_one":protected]=> array(0) { } ["_belongs_to":protected]=> array(0) { } ["_has_many":protected]=> array(0) { } ["_load_with":protected]=> array(0) { } ["_validation":protected]=> NULL ["_object":protected]=> array(14) { ["id"]=> NULL ["empresa_id"]=> NULL ["codi_compte"]=> NULL ["compte"]=> NULL ["tipus"]=> NULL ["saldo_deure"]=> NULL ["saldo_haver"]=> NULL ["saldo"]=> NULL ["nivell"]=> NULL ["ultim_moviment"]=> NULL ["client_id"]=> NULL...
这就是模型,但是我如何获取获取的数据?
在我看来也是这样:
foreach ($comptes as $row)
{
echo "<p>$row->codi_compte</p>";
}
?>
但我什么也没得到......
谢谢!
编辑
这不起作用:
$comptes = ORM::factory('compte');
$comptes->find_all();
但这行得通 $comptes = ORM::factory('compte')->find_all();
为什么?
这不起作用:
$comptes = ORM::factory('compte');
$comptes->where('empresa_id', '=', 2)->find_all();
但同样,这是可行的:
$comptes = ORM::factory('compte')->where('empresa_id', '=', 2)->find_all();
这个多行示例来自Kohana Web
【问题讨论】:
标签: kohana kohana-3 kohana-orm