Welcome Guest, Not a member yet? Register   Sign In
Calling Multiple Models in one Controller
#1

[eluser]amalik[/eluser]
Hi All,

I am creating a website where I need to output data from multiple models into a controller. Its a little forum application. For example on the user page I want to display all of the user data and the messages he got from other members and his posts and much more. This all is in different models. At the moment when I load more then one model into my controller it gives me errors. Can any one help me please. I want to know how can I load multiple models into one controller so I can extract data from them.

I am new to codeigniter. If I am asking a stupid question please forgive me.

Thanks in advance.
A Malik
#2

[eluser]InsiteFX[/eluser]
Well maybe is you show the error's you are getting maybe someone could help you!
#3

[eluser]amalik[/eluser]
Thanks a lot for your reply. The error is associated with including multiple modules. If I use any one of the module every thing is fine when I include more then one module it gives me errors. I am including them like
Code:
function __construct(){
  parent::__construct();
  
  $this->load->model("user_model");
  $this->load->model("albums_model");
}

and the error is some thing like this

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Albums::$albums_model

Filename: controllers/albums.php

Line Number: 33

line no 33 is

Code:
$user_albums =  $this->albums_model->select_albums_by_uid($uid);

I hope it is clear now

Thanks in advance
#4

[eluser]cbwd[/eluser]
Can you post the model code?

Also have you tried setting a different name for the model? Just something to try...

Code:
$this->load->model("albums_model",'whatever');
#5

[eluser]amalik[/eluser]
Thanks a lot for your reply. Yes I did. My Model code is
Code:
class Albums_model extends CI_Controller{
function __construct(){
  parent::__construct();
}

function select_albums_by_uid($uid){
  $query_string = "SELECT * FROM users_albums WHERE user_id = ?";
  $result = $this->db->query($query_string, array($uid));
  
  echo "In here";
  
  if($result->num_rows() == 1){
   $dataArray = $result->row();
   return $dataArray;
  }
  
  else{
   return false;
  }  
}
}
#6

[eluser]InsiteFX[/eluser]
This is wrong!
Code:
class Albums_model extends CI_Controller{

// should be...
class Albums_model extends CI_Model{
#7

[eluser]amalik[/eluser]
Thanks a lot for your reply.
Changed CI_Controller to CI_Model for all models but I am still getting the same error.
#8

[eluser]InsiteFX[/eluser]
Make sure you save them all to ./application/models and the filename should be all lower case...




Theme © iAndrew 2016 - Forum software by © MyBB