快速Codeigniter问题真的......我建立了一个电子商务网站,其中包含大量重复的menus
和submenus
等等。这是我的第一个Codeigniter项目,所以尽管一切正常,但它的结构并不精彩...
我的控制器非常bulky
且加载速度很慢。我现在正在尝试structure
我的控制器和模型 - 我猜我可能会将其中的大部分用于帮助器并让它们自动加载 - 但我有点不确定从哪里开始和什么可以去哪里;我正在寻找一些建议。
控制器:
<?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);
}
}
型号:
<?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';
}
}
}
等。等等。
谢谢!