2014年12月4日 星期四

[PHP] CI-VIEW include VIEW

從 MS 跳過來,兩星期了
還是有些不是很適應,也很疑惑,但其實只要把 MS 的觀念都丟了

是不難學的啦!


一般CI,多個VIEW要組在一起的基本寫法:
這是在controllers裡面的
$this->load->view('hearer');
$this->load->view('menu');
$this->load->view('footer');
以上看來是由上往下排,那左右呢?

第一個碰到的疑問


所以針對這個問題,去查了一下
其實是可以在VIEW裡直接include的

第一種、
這是在controllers裡面的,注意view的第三個參數要設為'true',預設為'false'
$viewfile['header'] = $this->load->view('header','',true);
$viewfile['footer'] = $this->load->view('footer','',true);
$this->load->view('menu',$viewfile);

這是在view裡面的
<?=$header?>
<?=$footer?>

第二種、
這是在view裡面的,直接include進來
<?php 
    $this->view('header'); 
    $this->view('footer'); 
?>

沒有留言:

張貼留言