开发者

kohana get next elements of a collection

开发者 https://www.devze.com 2023-02-16 23:26 出处:网络
I have a collection of elements : $products_asc =Model::factory(\'product\')->sale($sale_id)->category($category_id)->order_by(\'product_id\', \'asc\')->find_all();

I have a collection of elements :

$products_asc =Model::factory('product')->sale($sale_id)->category($category_id)->order_by('product_id', 'asc')->find_all();

and I want to make a next-previous navigator into this elements. (of course, for getting the previous ones I will开发者_JAVA技巧 have a $products_desc ordering)

My problem is: I want to make a function having the signature:

public function get_next_product($category, $sale, $id_product)

that will always give me the next product id. but I don't know how to do it. How exactly can i get the next element of the collection having only all the elements sorted ascending by the :

$products_asc =Model::factory('product')->sale($sale_id)->category($category_id)->order_by('product_id', 'asc')->find_all();


i have found the solution - for those who may also be in need:

        $previous = Model::factory('product')->sale($sale_id)->order_by('product_id','desc')->where('product_id', '<', $id)->find();    
        $next = Model::factory('product')->sale($sale_id)->where('product_id', '>', $id)->find();


Database_Result is a kind of Iterator object. Why dont use next($products_asc) and prev($products_asc) functions?

0

精彩评论

暂无评论...
验证码 换一张
取 消