Hi,
I have been tearing my hair out over this for about 3 hours, please can someone help?
Here is what I want to achieve...
On my home page I wish to have a sidebar widget/module which displays the latest 10 events from the events controller.
I started off trying to use the widget plugin, but could not get my head around it -[url=http://codeigniter.com/forums/viewthread/109584/#552597]Plugin widget[/url]
Next I read about extending the standard controller to MY_Controller, so in the MY_Controller I added the code from my events controller which retrieves the latest events using the events model, I presume this is the correct place to put this?
contents of MY_Controller
[code] function home_events() {
// load library
$this->load->library(array('table','validation','template'));
// load helper
$this->load->helper('url', 'form');
// load model
$this->load->model('event_model','',TRUE);
$this->load->model('location_model','',TRUE);
$data['base'] = $this->config->item('base_url');
// offset
$uri_segment = 3;
$offset = $this->uri->segment($uri_segment);
// load data
$events = $this->event_model->get_paged_list($this->limit, $offset)->result();
// generate pagination
$this->load->library('pagination');
$config['base_url'] = site_url('event/index/');
$config['total_rows'] = $this->event_model->count_all();
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
// generate table data
$this->load->library('table');
$this->table->set_empty(" ");
$this->table->set_heading('Name', 'Location', 'Date', 'Image', 'Actions');
$i = 0 + $offset;
foreach ($events as $event){
$this->table->add_row($event->name, $event->location, $event->date, $event->image_url,
anchor('event/view/'.$event->id,'view',array('class'=>'view'))
);
}
$data['table'] = $this->table->generate();
$data['home_events_view'] = $this->load->view('home_events', $tmp_data, TRUE);
$this->load->view('home', $data);
}
//end function home_events
[/code]
Next in my home view I try and load the home_events_view with the following -
<?php echo $home_events_view; ?>
When I load the homepage I get the following error - Message: Undefined variable: home_events_view Filename: views/home.php
Have I approached this the correct way?, can anyone spot where I have gone wrong? Im guessing that I need to put something in my home controller to retrieve the events data?
Any help would be appreciated, I have learnt so much lately about codeigniter and I love it, but embedding views has been a big snag!
Thanks Dan