2011-04-26 6 views
0


codeigniter에서 CSS 템플릿 만 구성하는 데 문제가 있습니다. 예 : 저는 codeigniter에서 초보자입니다. 어느 누구나 내가 그것을 구성하거나 튜토리얼을 구성 할 수 있다고 말할 수 있습니다. 당신이 내 나쁜 영어를 이해 바랍니다 .. 여기 codeigniter에서 CSS 템플릿을 구성하는 데 도움이 필요합니다.

는보기 페이지에서 컨트롤러 페이지에서 home.php

<?php $this->load->view('header_final');?> 



    <div id="page"> 
     <div id="page-bgtop"> 
      <div id="page-bgbtm"> 
       <div id="content"> 
        <div class="post"> 
         <h2 class="title"><a href="#">Home</a></h2><br> 

         <div class="entry"> 
          <p><img src="<?=site_url();?>images/img08.jpg" width="538" height="200" alt="" /></p> 
          <p>Sylhet Engineering College (SEC), established in the year 2007 under the School of Applied Science and Technology, Shahjalal University of Science and Technology is best of its kind with a motto to produce the best in class engineers for the 21st century in Bangladesh. There are five universities of Engineering and Technology and some private universities in the country for providing engineering education at B.Sc level which is not sufficient to meet the requirement of today's fast paced engineering sector of Bangladesh. As a divisional city of Bangladesh, Sylhet had no engineering institute. So the Government of Peoples Republic of Bangladesh has established Sylhet Engineering College with a vision to expand the engineering education of Bangladesh as an engineering faculty section of Shahjalal University of Science and Technology.</p> 

         </div> 
        </div> 



        <div class="post"> 


        </div> 
        <div style="clear: both;">&nbsp;</div> 
       </div> 
       <!-- end #content --> 


<?php $this->load->view('footer_final');?> 


home.php

<?php 

class Home extends Controller { 

    function Home() 
    { 
     parent::Controller(); 

    } 

    function index() 
    { 

     $this->load->view('home'); 


    } 
} 

힌트 내 코드

입니다 :

header_final.phpfooter-final.php

답변

3

CodeIgniter를 사용하면 동시에 여러보기를로드 할 수 있습니다. 컨트롤러에 뷰로드를 남기고 싶습니다. 따라서 컨트롤러에서 머리글보기를로드 한 다음 렌더링 할 실제보기를로드 한 다음 바닥 글보기를로드해야합니다. 완료되면 다음과 같이 표시됩니다.

function index(){ 
    $this->load->view('header_final'); 
    $this->load->view('home'); 
    $this->load->view('footer_final'); 
} 

그런 다음 home.php보기에서 모든보기로드를 제거하십시오.

0

올바른 방법은 컨트롤러를 사용하여보기를 조작하는 것입니다. 기본 컨트롤러는 "system/app/config/routes.php"파일에 지정되어 있습니다. 매개 변수 "default_controller"는 응용 프로그램에 기본적으로 사용할 컨트롤러를 알려줍니다.

Carl이 말한 것처럼 필요한 뷰를로드해야하는 모든 코드 행을 배치했으면 default_controller가이 컨트롤러를 가리킬 수 있습니다. 함수 인덱스는 컨트롤러가 사용하는 기본 함수입니다.

일단 계속 진행하면 모든 페이지에이 머리글과 바닥 글이 필요하므로 맞춤 컨트롤러를 만들어야 할 수도 있습니다. 나는 "system/app/core/MY_Controller.php"(Code igniter 2.X, 다른 버전과 같지 않음) 파일을 addind하여이 컨트롤러를 확장했다. 이 컨트롤러 내의 코드는 다음과 같습니다

<?php 

class MY_Controller extends CI_Controller { 

    function __construct() { 
     parent::__construct(); 
    } 
    public function loadHeader($data = Array(),$customHeader = 'parts/header'){ 
     $this->load->view($customHeader,$data); 
    } 
    public function loadFooter($data = Array(),$customFooter = 'parts/footer'){ 
     $this->load->view($customFooter,$data); 
    } 
    public function loadSidebar($data = Array(),$customSidebar = 'parts/sidebar'){ 
     $this->load->view($customSidebar,$data); 
    } 
} 

그럼 내 컨트롤러에서 나는 같은 것을 할 :

<?php 

class Articles extends MY_Controller { 
    public function __construct() { 
     parent::__construct(); 
    } 
    /** 
    * Controller for all news. 
    * will be used as home controller. 
    */ 
    public function index() { 
     //Needed helper 

     //End helper 
     $data = Array(); 
     //Fill the array for the header part 
     $data["header"] = Array(); 
     $data["header"]["title"] = "Articles shelf"; 
     $data["header"]["logo"] = "David Francoeur"; 
     $data["header"]["slogan"] = "just a blog about me and knowledge..."; 
     $this->loadHeader($data["header"]);// I would add a second parameter for a custom header. 
     //Fill the array for the rest of the pages 
     $data["main"] = Array(); 
     $this->load->model('Article'); 
     $data["main"]["query"] = $this->Article->get_last_ten_entries(); 
     $this->load->view('article', $data["main"]); 
     //Fill the array for the right sidebar 
     $data["sidebar"] = Array(); 
     $this->loadSidebar($data["sidebar"]); 
     //Fill the array for data concerning the footer 
     $data["footer"] = Array(); 
     $this->loadFooter($data["footer"]);//I would add a second parameter for a custom footer. 
    } 

} 
필요하지 않은 경우

당신은 또한 사용자 정의 컨트롤러에 하나의 함수를 사용할 수 있습니다 사용자 정의 헤더 나 같은 바닥 글 뭔가 :

<?php 

클래스 MY_Controller가 {

CI_Controller를 확장
function __construct() { 
    parent::__construct(); 
} 
public function loadView($data = Array(),$view){ 
    $this->load->view("header_final"); 
    $this->load->view($view,$data); 
    $this->load->view("footer-final"); 
} 
} 

여러분에게 달려 있습니다!

관련 문제