Welcome Guest, Not a member yet? Register   Sign In
load model in view for header
#1

[eluser]bigtimslim[/eluser]
My site has a header that I want to print a random entry from a db table in. How would you tackle this? I tried just directly loading the model and printing the result and such in the header view, but am getting an error: "Call to a member function get_wally() on a non-object"

Code:
Model function:

function get_wally()
{
   $query = $this->db->query("SELECT wally_says FROM wally ORDER BY RAND() LIMIT 1");
   return $query->row();
}

from View:

<div id="wallysays" class="round">
   &lt;?php
       $this->load->model('Wally_model');
       $wally = $this->wally_model->get_wally();
       echo $wally->wally_says;
   ?&gt;
</div>


I must be doing something stupid here. Help me out? Smile


Messages In This Thread
load model in view for header - by El Forum - 03-15-2009, 09:45 PM
load model in view for header - by El Forum - 03-15-2009, 11:36 PM
load model in view for header - by El Forum - 03-16-2009, 01:46 AM
load model in view for header - by El Forum - 03-16-2009, 01:50 AM
load model in view for header - by El Forum - 03-16-2009, 03:46 AM
load model in view for header - by El Forum - 03-16-2009, 04:25 AM
load model in view for header - by El Forum - 04-13-2011, 09:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB