久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 codeigniter 實現動態菜單/頁眉/頁腳的最佳方

Best way to implement dynamic menus/headers/footer using codeigniter(使用 codeigniter 實現動態菜單/頁眉/頁腳的最佳方法)
本文介紹了使用 codeigniter 實現動態菜單/頁眉/頁腳的最佳方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我只是想知道使用 codeigniter 實現帶有更改內容(例如通知)的菜單、頁眉和頁腳的最佳方法/實踐.

I was just wondering the best way/practice to implement menus, headers and footers with changing content such as notifications using codeigniter.

例如,我在標題菜單中有一個警報,該警報鏈接回數據庫中的數據,并且每次加載頁面時我都需要檢查更改.最初我以為我可以每次都使用 $this->load->view('header') 調用標題,但這意味著我需要一個全局函數來計算警報的任何更改,然后將其傳遞給標題視圖,每次都不好!

For example say I had an alert within the header menu that linked back to data within a database and I needed to check for changes each time a page is loaded. Initially I thought I could call the header using $this->load->view('header') each time, but this would mean I would need a global function to work out any changes on alerts and then pass that to the header view, each time, not good!

我想我需要一種全局方式來調用從任何控制器加載網站標題(菜單)的函數,該控制器計算出內容并相應地顯示視圖.

I guess I need a global way to call function that loads the website header (menu) from any controller which works out the content and displays the view accordingly.

推薦答案

例如一個顯示博客頁面的控制器.
在您的控制器構造函數中 - 定義您的博客視圖文件所在的文件夾和模板名稱

so for example a controller that shows blog pages.
in your controller constructor - define the folder your blog view files are in and the template name

// the folder your content files are in 
$this->templatefolder = 'blog' ;
// the template name
$this->view_template = 'blog_template' ; 

在您準備調用某些視圖時的方法中

in a method when you are ready to call some views

$data['content01'] = 'search_articles';
$data['content02'] = 'main_article';
$data['content03'] = 'suggested_articles';
$this->load->view( $this->view_template, $data ); 

模板本身視圖/blog_template.php

the template itself views/blog_template.php

// opening html etc that is generic to website
$this->load->view('tmpl_open');

// so if the header has to be dynamic
// get the header from a model (or library etc) 
// and either pass the header content or just echo it out directly 
$this->load->model('header');

if( ! $newHeader = $this->header->returnNewHeader() )
{

  // fallback if the header doesn't come back from the model 
  $this->load->view('default_header');

} 
else
{   echo $newHeader ;     } 

// this is optional but IF the template folder is not set 
// we have a default folder called 'pages' to look in for the content views 

// but in this example the folder is set to be 'blog' 
// so the blog view files will be in application/views/blog/search_articles.php etc etc
if( isset($this->templatefolder)){

$templatefolder = $this->templatefolder . '/' ;  }

else { $templatefolder = 'pages/'; }

// header that is specific for the content 
$this->load->view($templatefolder . 'header');

// so in this specific example its going to load 3 view files, but this part is completely flexible 
if(isset($content01))
$this->load->view($templatefolder.$content01);

if(isset($content02))
$this->load->view($templatefolder.$content02);

if(isset($content03))
$this->load->view($templatefolder.$content03);

if(isset($content04))
$this->load->view($templatefolder.$content04);

if(isset($content05))
$this->load->view($templatefolder.$content05);

if(isset($content06))
$this->load->view($templatefolder.$content06);

if(isset($content07))
$this->load->view($templatefolder.$content07);

if(isset($content08))
$this->load->view($templatefolder.$content08);

// example of an optional file that you can uncomment for testing 
// $this->load->view('objecttesting');

// bottom nav bar generic to website
$this->load->view('tmpl_footer');

// closing html etc generic to website
$this->load->view('tmpl_close'); 

這篇關于使用 codeigniter 實現動態菜單/頁眉/頁腳的最佳方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 91久色| 免费视频一区二区 | 四虎影音| 亚洲精精品 | 福利视频亚洲 | 久久免费视频1 | 国产99久久 | 日日干日日射 | 亚洲视频精品 | 免费看黄视频网站 | 久久久看| 视频在线观看亚洲 | h在线免费观看 | 啪啪免费网站 | 欧美激情一区二区 | 国产精品久久久久久妇女 | 亚洲国产精品一区二区三区 | 亚洲高清免费观看 | 天天操天天射综合 | 中文字幕第7页 | 国产麻豆乱码精品一区二区三区 | 日韩成人在线观看 | 日韩在线小视频 | 国产精品不卡 | 91麻豆精品一区二区三区 | 色婷婷在线视频 | 欧美一级二级视频 | 欧美a级成人淫片免费看 | 色爽女 | 亚洲三区视频 | 国产视频中文字幕 | 午夜小视频在线播放 | 免费日韩av| 91视频网址 | 欧美精品在线一区 | 国产精品综合 | 欧美精品一区在线观看 | av资源中文在线天堂 | 欧美精品一区在线发布 | 午夜免费视频 | 天天干天天干 |