It looks like you're new here. If you want to get involved, click one of these buttons!
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once(FUEL_PATH.'models/base_module_model.php');
class Sidebar_model extends Base_module_record {
public function get_recent_posts($num = 5)
{
$recent_posts = array();
// .. logic
return $recent_posts;
}
public function get_recent_comments($num = 5)
{
$recent_comments = array();
// .. logic
return $recent_comments;
}
public function get_upcoming_event()
{
// .. logic example
$today = date("Y-m-d H:i:s");
$event = fuel_model('events', array(
'find' => 'one',
'order' => 'sticky, start_date desc',
'where' => "end_date >= '$today'",
'module' => 'events',
'return_method' => 'object'
));
return $event'
}
}
?>
$autoload['model'] = array(
'sidebar_model'
);
$sidebar_model = $this->sidebar_model;
$vars['sidebar'] = array();
$vars['sidebar']['recent_posts'] = $sidebar_model->recent_posts;
$vars['sidebar']['recent_comments'] = $sidebar_model->recent_comments;
A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Model.php
Line Number: 5572
A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Model.php
Line Number: 5573
A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Model.php
Line Number: 5572
A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Model.php
Line Number: 5573
Comments
require_once(FUEL_PATH.'models/base_module_model.php'); class Sidebar_model extends Base_module_record {
Perhaps if you declare the model as
class Sidebar_model extends CI_Model {
fuel_model
to get the data from fuel, and also the fuel_blog module$recent_posts = $this->_CI->fuel_blog->get_recent_posts(3);
. Is that what you mean by using fuel? Because if so, then yesThe original problem was the way I was calling the data.
Instead of
$vars['sidebar']['recent_posts'] = $sidebar_model->recent_posts;
I should be doing$vars['sidebar']['recent_posts'] = $sidebar_model->get_recent_posts();
. I guess the get_ prefix isn't translating well.Now the other problem I have is that I have 3 views, home, event, and location.
On the home view, in the sidebar model
$this->_CI->fuel_blog
is defined, however on the other views sidebar_model reports that it's null. For example I have line 11 which is$recent_posts = $this->_CI->fuel_blog->get_recent_posts(3);
, running this on the home view is fine, although on the event or location view I get:Fatal error: Call to a member function get_recent_posts() on null in fuel\application\models\sidebar_model.php on line 11
What's up with that? How can I find the fuel_blog from here?