public function index($tieudekd = null, $page = 0) { $catDB = new CatalogDB(); $postDB = new PostDB(); $catList = $catDB->getAllCategory(); // Lay tat ca danh sach $catMenu = $catList->getCatalogParent(); // Lay tat ca catalog cha if ($page == 0) { $strid = substr($tieudekd, strlen($tieudekd) - 3); $strpos = strpos($strid, '-'); $idc = substr($strid, $strpos + 1); try { $index = intval($idc); if ($idc == "23" || $idc == 23) { redirect(base_url() . 'huong-dan-dat-hen-kham-90.html'); } else { if ($idc == "31" || $idc == 31) { redirect(base_url() . 'chinh-sach-gia-199.html'); } } if (preg_match('/^[a-z]+$/', $idc)) { $data['title'] = $tieudekd; if ($tieudekd == 'chuyen-de-bao-quy-dau') { redirect(base_url() . 'bao-quy-dau/'); } } } catch (Exception $e) { } $postList = $postDB->getAllPost(); $idc = intval($idc); $idLoai = $idc; $cat = $catList->findIdLoai($idc); // kiem tra ko ton tai cat thi redirect trang ko tim thay $catListParent = $catList->getCatalogParent(); if ($cat->getParent() == 0 || $cat->getParent() == '0') { $catParent = null; } else { $catParent = $catListParent->getCatalogIdLoai($cat->getParent()); } $postShow = $postList->getBaiViet($idc, 7); if (!$catParent) { $catFirst = $catList->getCatalogFirst($idc); if ($catFirst) { $postTopRead = $postDB->getTopPopularRead(5, $catFirst->getIdLoai()); } else { $postTopRead = null; } } else { $postTopRead = $postDB->getTopPopularRead(5, $idc); } $breadcum = ""; if ($catParent) { if (!preg_match('/^[0-9]{1,5}$/', $idLoai)) { throw new Exception('id Loai khong hop le'); } $breadcum = "<a href='" . base_url() . "" . $catParent->getTieuDeKD() . "'>" . $catParent->getTieuDe() . "</a>"; } if ($cat) { $breadcum .= "<a href='" . base_url() . "" . $cat->getTieuDeKD() . "'>" . $cat->getTieuDe() . "</a>"; } else { $breadcum = "<a href='" . base_url() . "" . $cat->getTieuDeKD() . "'>" . $cat->getTieuDe() . "</a>"; } //else $breadcum = "<a href='". base_url()."index.php/tin-suc-khoe'>Tin sức khỏe</a>"; // Neu co cat parent la danh muc con if ($catParent) { $data = array("breadcum" => $breadcum, "CatMenu" => $catMenu, "catList" => $catList, "postShow" => $postShow, "cat" => $cat, 'postTopRead' => $postTopRead->getList()); $data['accordion'] = $catDB->hienthiLoaiBaiVietCon($idLoai); $data['page'] = $page; $data['postDB'] = $postDB; $data['catDB'] = $catDB; $data['hasCatsub'] = false; $data['bai_viet_phone'] = $catDB->hienthiLoaiBaiVietCuaMotLoai($idLoai); $data['menu'] = $this->CatalogDB->showMenu(); $this->load->view('catalog/index', $data); } else { // Lay cac menu con $catSub = $catList->getCatalogChildren($idc); $data = array("breadcum" => $breadcum, "CatMenu" => $catMenu, "catList" => $catList, "postList" => $postList, "cat" => $cat, "catSub" => $catSub); if ($postTopRead != null) { $data['postTopRead'] = $postTopRead->getList(); } else { $data['postTopRead'] = $postTopRead; } $data['accordion'] = $catDB->hienthiLoaiBaiVietCon($idLoai); $data['page'] = $page; $data['postDB'] = $postDB; $data['hasCatsub'] = true; $data['catDB'] = $catDB; $data['menu'] = $this->CatalogDB->showMenu(); $this->load->view('catalog/list', $data); } } else { $strid = substr($tieudekd, strlen($tieudekd) - 3); $strpos = strpos($strid, '-'); $idc = substr($strid, $strpos + 1); $cat = $catList->getCatalogIdLoai($idc); $catListParent = $catList->getCatalogParent(); $catParent = null; if ($cat) { $catParent = $catListParent->getCatalogIdLoai($cat->getParent()); } if ($catParent) { $breadcum = "<a href='" . base_url() . "" . $catParent->getTieuDeKD() . "'>" . $catParent->getTieuDe() . "</a>"; } if ($cat) { $breadcum .= "<a href='" . base_url() . "" . $cat->getTieuDeKD() . "'>" . $cat->getTieuDe() . "</a>"; $postTopRead = $postDB->getTopPopularRead(5, $cat->getIdLoai()); $postShow = $postDB->paganition($cat->getIdLoai(), $page, 7); $cat = $catList->getCatalogIdLoai($cat->getIdLoai()); $data = array("breadcum" => $breadcum, "CatMenu" => $catMenu, "catList" => $catList, "postShow" => $postShow, "cat" => $cat, 'postTopRead' => $postTopRead->getList()); $data['page'] = $page; $idLoai = $idc; $data['bai_viet_phone'] = $catDB->hienthiLoaiBaiVietCuaMotLoai($idLoai); $data['postDB'] = $postDB; $data['hasCatsub'] = false; $data['catDB'] = $catDB; $data['menu'] = $this->CatalogDB->showMenu(); $this->load->view('catalog/index', $data); } else { redirect(base_url() . 'khong-tim-thay-trang/1/'); } } }
public function test3($idLoai) { if (!preg_match('/^[0-9]{1,5}$/', $idLoai)) { throw new Exception('id Loai khong hop le'); } $this->load->model('CatalogDB'); $catDB = new CatalogDB(); $data['accordion'] = $catDB->hienthiLoaiBaiVietCon($idLoai); $this->load->view('catalog/test', $data); }