![]() |
Codeigniter controllers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Codeigniter controllers (/showthread.php?tid=84704) |
Codeigniter controllers - GrehnanSondra - 11-02-2022 Quick Codeigniter question really... I built an eCommerce site with a lot of repetitive menus and submenus etc. It was my first Codeigniter project, so while it all works, it's not structured brilliantly... My Controllers are quite bulky and slow to load. I'm now looking at trying to structure my Contollers and Models - I'm guessing I can probably put most of it into helpers and have them echatrandom echatspin autoloaded for ease - but I'm a bit unsure where to start and what can go where; I'm looking for some advice. Controller: <?php class Seixweb_live_brands extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('Seixweb_live_model'); } public function product_lookup_by_id($str1) { if ($this->uri->segment(3)) { $filter = $this->uri->segment(3); } else { $filter = 1; } $config = array( 'base_url' => base_url() . '/brands/' . $str1 . '/' . $filter . '/', 'total_rows' => $this->Seixweb_live_model->brands_num_rows(), 'per_page' => 30, 'uri_segment' => 4 ); $this->pagination->initialize($config); $query = $this->Seixweb_live_model->brands_row(); $data = array( 'title' => $query->sw_brand . ' | Fragrance, Skin Care & Shaving Brands for Men | eMale Grooming', 'description' => $query->sw_brand, 'keywords' => $query->sw_brand, 'heading' => $query->sw_brand, 'total_rows' => $config['total_rows'], 'filter_url' => base_url() . 'brands/' . $str1 . '/', 'header1_result' => $this->Seixweb_live_model->submenu1_result(), 'header2_result' => $this->Seixweb_live_model->submenu2_result(), 'header3_result' => $this->Seixweb_live_model->submenu3_result(), 'header4_result' => $this->Seixweb_live_model->submenu4_result(), 'header5_result' => $this->Seixweb_live_model->submenu5_result(), 'tpl_result' => $this->Seixweb_live_model->menu_result(), 'view_result' => $this->Seixweb_live_model->brands_result() ); $this->load->view('seixweb_live_header_view', $data); $this->template->load_seixweb_live('seixweb_live_view', $data); $this->load->view('seixweb_live_footer_view', $data); } } Model: <?php class Seixweb_live_model extends CI_Model { public function __construct() { parent::__construct(); } public function brands_result() { $str1 = $this->uri->segment(2); if ($this->uri->segment(3) == 2) { $filter = 'a.search_price ASC'; } elseif ($this->uri->segment(3) == 3) { $filter = 'a.search_price DESC'; } elseif ($this->uri->segment(3) == 4) { $filter = 'b.timestamp DESC'; } elseif ($this->uri->segment(3) == 5) { $filter = 'discount DESC'; } else { $filter = 'b.sw_brand ASC, b.sw_subbrand ASC, b.sw_product ASC, b.sw_size ASC, b.sw_unit ASC'; } } } etc. etc. etc. Thanks! RE: Codeigniter controllers - SharphSonirak - 11-03-2022 u r using autoload want to know how can u use it in controller??? You want crate helper file to use more time and for flexible? |