[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 */