PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Importing a model in header view class CodeIgniter

 March 14, 2022     codeigniter, php     No comments   

Issue

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.


Solution

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.



Answered By - silentwasd
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing