Welcome Guest, Not a member yet? Register   Sign In
Help with Controller
#1

[eluser]Unknown[/eluser]
I just started using CI about weeks ago, and I'm trying to experiment what this framework can do by creating my own CMS-sort of portal.

I have a page called dashboard (editor.php). It is basically everything - events, uploads, posts, etc.
Now, I have a controller for dashboard which is admin.php

It looks like this:
Code:
class Admin extends CI_Controller
{
function __construct()
{
  parent::__construct();
  $this->is_logged_in();
}

function index()
{
  $this->load->view('login');
}

function dashboard()
{
  $this->load->model('gallery_model');
  $this->load->model('site_model');
  
  $data = array();
  
  $data['images'] = $this->gallery_model->get_images();
  $data['events'] = $this->site_model->get_events();

  $this->load->view('admin/editor', $data);
}
function is_logged_in()
{
  $is_logged_in = $this->session->userdata('is_logged_in');
  
  if (!isset($is_logged_in) || $is_logged_in != true)
  {
   echo '[removed]alert("You are not logged in.");[removed]';
   redirect('login', 'refresh');
  }
}
}

Now, basically my problem is at the 'dashboard' function. Because I need to call 2 or more models. Like you can see:

Code:
$this->load->model('gallery_model');
$this->load->model('site_model');

And of course, I need to call their methods.

Code:
$data['images'] = $this->gallery_model->get_images();
$data['events'] = $this->site_model->get_events();

But, it's giving me errors:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Admin::$site_model
Filename: controllers/admin.php
Line Number: 24

Fatal error: Call to a member function get_events() on a non-object in ...\application\controllers\admin.php on line 24

It's pertaining to the line where I am calling the get_events function.

I've checked my config files and see everything is loaded okay.

Code:
$autoload['libraries'] = array('database', 'session', 'xmlrpc', 'parser');

because I was expecting to show the events in the left sidebar and the latest uploads (of images) to be shown on the right part of the contents.

I already tried searching some solutions around the net, but didn't work for me. I also saw some same topics about my problem, but we have quite a different scenario.

Can anyone help me out!?
Thank you.


Messages In This Thread
Help with Controller - by El Forum - 05-22-2013, 02:23 AM
Help with Controller - by El Forum - 05-22-2013, 04:19 AM
Help with Controller - by El Forum - 05-22-2013, 07:54 PM
Help with Controller - by El Forum - 05-23-2013, 07:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB