[請益] CI裡面header檔案的寫法 codeigniter

看板PHP作者 (smile_ting)時間13年前 (2012/08/28 08:34), 編輯推噓2(2010)
留言12則, 5人參與, 最新討論串1/3 (看更多)
我把 header 檔獨立出來成一個view 比如說在 index的view裡面 我會先load $this->load->view('header',$data); 但是因為這個header檔案我有點把它當 common fuction在用。 每個view都會去load 這個 header檔 但是每個view 可能需要額外 load js/css 之類的檔案還會有所差異 所以我作法如下 在 index view 裡面 <? $this->load->view('header',$data, TRUE); //下面擺上我在個別頁面所需要的檔案 <script type="text/javascript" src="assets/js/order_tip.js"> ~~~~ ?> </head> //最後用</head> 結束 這個head block 但是這樣卻不work , 我用firebug看。 HTML下面 <head> </head> 是空的 Script tab 裡面也是一大堆 js 檔案根本就沒有load進來。 我的 header view 結構如下 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "" rel="nofollow">http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=8, IE=9, IE=10" > ~~~~~~ 不會有結尾的 </head> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 119.77.136.156

08/28 09:13, , 1F
你在php tag裡擺<script>...他會當字串處理吧
08/28 09:13, 1F

08/28 09:13, , 2F
然後你沒echo而是直接放上,竟然沒發生錯誤?
08/28 09:13, 2F

08/28 12:02, , 3F
lol 你要搞清楚HTML 就是要放在HTML, PHP是PHP
08/28 12:02, 3F

08/28 18:23, , 4F
有錯誤啊,只是沒顯示出來,所以後面的</head>就沒了
08/28 18:23, 4F

08/28 18:24, , 5F
比較好的作法是$data['js']=array('a.js','b.js');
08/28 18:24, 5F

08/28 18:24, , 6F
到header.php再用foreach一個一個放<script>
08/28 18:24, 6F

08/28 19:54, , 7F
樓上兩樓 我覺得我並不是在 php tag 百 script
08/28 19:54, 7F

08/28 19:55, , 9F
我作法是類似去 include header.php 這檔案裡面本身就可以
08/28 19:55, 9F

08/28 19:55, , 10F
是純html tag 沒有問題吧
08/28 19:55, 10F

08/29 02:27, , 11F
不確定是不是這個的問題 $this->load->view()的第三個參數
08/29 02:27, 11F

08/29 02:27, , 12F
如果是true的話 會是回傳一個字串 而不是直接echo出來
08/29 02:27, 12F
文章代碼(AID): #1GF18ej9 (PHP)
文章代碼(AID): #1GF18ej9 (PHP)