[英]Codeigniter if controller
首先很抱歉,如果它是一個菜鳥問題。
但是在codeingiter中這樣做是有可能的,就像我有一個側邊欄但我只想在2頁中加載它一樣
if(controller == 'blog') {
//load sidebar
}
就像在wordpress中,如果is_page
使用$this->router->fetch_class()
if($this->router->fetch_class() == 'blog') {
//load sidebar
}
$this->uri->segment(2)
在大多數情況下也可以使用,但是在某些情況下,例如mod_rewrite
或使用subfolder
或route
它可能會失敗。
更簡單地說,您可以這樣做。
$controller_name = $this->CI->router->fetch_class();
if($controller_name === "your_controller_name")
{
//your logic
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.