Welcome Guest, Not a member yet? Register   Sign In
Loading models in helpers.
#1

[eluser]ram4nd[/eluser]
I want to load a model in helper, but I have recursive function and it loads the model 100 times again and again if I load that page. How can I take the loading out of mu funcion.

My helper:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function get_main_category($category_id) {
    $CI = get_instance();
    $CI->load->model('categories_model');
    static $category, $up_category;
    //get category
    $category = $CI->categories_model->get_category($category_id);
    //get upper level category
    $up_category = $CI->categories_model->get_category($category->parent_id);
    //if upper category parent_id is 0, return category name
    if(empty($up_category->parent_id))
        return $category->name;
    //if upper category parent_id isn't 0, return get_main_category($category->parent_id)
    else
        return get_main_category($category->parent_id);
}

/* End of file categories_helper.php */
/* Location: ./system/application/helpers/categories_helper.php */


Messages In This Thread
Loading models in helpers. - by El Forum - 03-20-2010, 12:54 AM
Loading models in helpers. - by El Forum - 03-20-2010, 01:50 AM
Loading models in helpers. - by El Forum - 03-20-2010, 02:29 AM
Loading models in helpers. - by El Forum - 03-20-2010, 02:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB