Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - unable to load multiple views in controller

Tags:

codeigniter

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>
like image 312
Lynnie Avatar asked Mar 23 '26 01:03

Lynnie


2 Answers

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>
like image 188
Azam Alvi Avatar answered Mar 26 '26 02:03

Azam Alvi


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.

like image 24
Ganesh RJ Avatar answered Mar 26 '26 03:03

Ganesh RJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!