3

Hi everyone thank you for taking time to look at my question.

I have tried to run view (site_nav, site_header and site_footer) together only and it worked fine.

When I tried to run view (view_home) and the models it also worked fine.

However when I run all the views and models together, the view (site_nav, site_header and site_footer) does not work.

Could anyone please help?

public function home(){
    $this->load->model("model_cms_home");
    $data["results"] = $this->model_cms_home->getData("cms_home");
    $this->load->view("site_nav");
    $this->load->view("site_header");
    $this->load->view("view_home", $data);
    $this->load->view("site_footer");
}


VIEW("view_home")



<div id="home_hat1"> <img src="<?php echo base_url(); ?>pics/home_hat1.jpg"> </div>


<div id="content">

    <div id="dinner">

   <div class="home_title">

     <?php
    $query = $this->db->query("SELECT `title` , `text1` FROM `cms_home` WHERE       `ID` =1");

    if ($query->num_rows() > 0){
    $row = $query->row_array();

        echo $row['title'];

    }           
    ?>
  </div>

<div class="home_content">

    <?php
    $query = $this->db->query("SELECT `title` , `text1` FROM `cms_home` WHERE `ID` =1");

    if ($query->num_rows() > 0){
    $row = $query->row_array();

        echo $row['text1'];

    }           
    ?>
</div>

</div>
6
  • 1
    What doesn't work exactly? Do you get a blank page? Is your page not rendered correctly? Commented Dec 13, 2012 at 5:06
  • I get view("view_home") only with the correct data passed into it. But I don't get my header, nav or footer view loaded. Commented Dec 13, 2012 at 5:21
  • btw thanks for replying I really appreciate it! =) Commented Dec 13, 2012 at 5:21
  • That's weird. Can you post your view_home view in your question? I suspect something is wrong in it. Commented Dec 13, 2012 at 5:38
  • 3
    You shouldn't have queries in your view files. They should be in functions in the model, called from the controller, and the data passed to the views as an array. Commented Dec 13, 2012 at 7:26

2 Answers 2

3

You cannot call multiple view in one controller function. This can be done into view. I suggest you that you should first create a templete and in that template call your views like this

templete.php

<html>
<head>
<body>
   $this->load->view("site_nav");
   $this->load->view("site_header");
   <?php echo $content; ?>
   $this->load->view("site_footer");
</body>
</head>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

You can call view inside another view/template. But it does not mean you cannot call view inside controller.Please learn more CI3 CI2
1

MY suggestion is to call other page in view_home using include();. You cant see other pages as the last page will be called according to your code. If you put an alert in each page you will know it has actually called all the pages.

2 Comments

Ahhh sorry guys it is a silly mistake. I have made a comment to myself at the bottom of the view_home page and hence it didnt work. I have remove the comment and it is working fine now. Thanks Maxime for pointing out where the problem could be and everyone who tried to help. I really appreciate it! =)
No problem. Although, you should really implement what @Jeemusu suggested. (No queries in your view, only in a model that is called by your controller.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.