Home > Enterprise >  Importing a model in header view class CodeIgniter
Importing a model in header view class CodeIgniter

Time:11-15

Currently I have a index page where I'm showing the header, the content body and the footer for all my pages which looks like so:

<!--include header --->
    <?php $this->load->view('include/header');?>
    <div class="container"><?php $this->load->view($page); ?></div>
    <!--include footer --->
    <?php $this->load->view('include/footer') ;?>

Now in my include/header I have a <li> tag which takes reference from one of my models to show the count of a particular status for which I'm adding a statement at the top of my header class to get the model:

<?php $main['count']=$this->dashboard_model->combined(); 
?>
...
<li>
    <ul>
        <li><a href="leads/">Active Leads (<?php echo $count[0]["active"] ?>)</a></li>
    </ul>
</li>

Now this shows the count when I'm in my dashboard page, but when I switch to any other page it gives and error message saying Undefined property: CI_Loader::$dashboard_model at line 1.

CodePudding user response:

It means that the model not loaded in other pages. On your dashboard page the "dashboard_model" model was loaded before you use it in the header. You need to load model before use it on other page.

  • Related