Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

how to load view into another view codeigniter 2.1?

Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this

$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);

the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Two ways of doing this:

  1. Load it in advance (like you're doing) and pass to the other view

    <?php
    // the "TRUE" argument tells it to return the content, rather than display it immediately
    $data['menu'] = $this->load->view('menu', NULL, TRUE);
    $this->load->view ('home', $data);
    
  2. Load a view "from within" a view:

    <?php
    // put this in the controller
    $this->load->view('home');
    
    // put this in /application/views/home.php
    $this->view('menu');
    echo 'Other home content';
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...