duanhuang3074 2016-05-04 09:27
浏览 52
已采纳

Kohana查询生成器返回

We have a CMS written in Kohana 2.3.x (yes, we know it is an old one). When I use the query builder like this:

$obj = ORM::factory('product')->where(array_of_wheres)->find_all()

than the $obj will be an ORM_Iterator.

But when I write something like this:

$obj = ORM::factory('product');
if($something)
    $obj->where(array_of_wheres);
else
    $obj->where(array_of_other_wheres);
$obj->find_all();

Than the $obj will be a Product_Model instead of ORM_Iterator.

Can someone explain why is this happening?

Thanks, Dave.

  • 写回答

1条回答 默认 最新

  • duanmei1536 2016-05-11 13:16
    关注

    In first example $obj is result of find_all() function that is a ORM_Iterator called by on anonymous object of Product Model.

    But in 2nd example $obj is ORM object for Product Model. When you call find_all function it returns result as ORM_Iterator it does not modify original object.

    Here is correct way to do it

    $model = ORM::factory('product');
    if($something)
        $model->where(array_of_wheres);
    else
        $model->where(array_of_other_wheres);
    $obj = $model->find_all();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)