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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败