How to display data from the database using models and custom helpers?

前端 未结 1 1871
青春惊慌失措
青春惊慌失措 2021-01-28 09:21

I am currently creating a new application feature where in I want to dynamically change the values of page headers, page header titles, and breadcrumbs that are fetched from dat

相关标签:
1条回答
  • 2021-01-28 09:52

    I just figured out a way on how to do this. The key is to get the id of the menu name from the database and return it as a row and in the custom helper, just call the id of the menu name from the database. Here is how I did it:

    Here is my model:

            function get_page_menu_names($menu_id)
           {
               $this->db->select('menu_name');
    
               $this->db->from('menu_master');
    
               $this->db->where('menu_id', $menu_id);
    
               $query = $this->db->get();
    
               $menu_name_row = $query->row();
    
               if(isset($menu_name_row))
               {
                 return $menu_name_row->menu_name;
               }            
           }
    

    And here is how I called it from the helper that I wrote out:

    $page_header_array['inventory_master_listing'] = array(
    
                "breadcrumbs" =>  array(
                    array('title'=>'Home','url'=>base_url()),
                    array('title'=> $this->my_model_name->get_page_menu_names(1),'is_active'=>TRUE),
                ),
                "page_title"  =>  $this->my_model_name->get_page_menu_names(1),
                "page_header_title" =>  $this->my_model_name->get_page_menu_names(1).' : '.$project_title
    
            );
    
    0 讨论(0)
提交回复
热议问题