Welcome Guest, Not a member yet? Register   Sign In
Loading a Model is not working for me. Please help
#1

[eluser]n00bPhpCoder[/eluser]
Well after that URL problem that was fixed a while ago here i am again with another problem that i cannot figure out myself.

According to the manual when loading a model and if you want to assign it to a variable you do this

$this->load->model('modelfilename','modelnameyouwant');

then you can do this

$this->modelnameyouwant->function();

But everything seems to work fine before i uploaded all my files to my web host.

This is the error

Call to a member function on a non-object


it seems that $this->modelnameyouwant is not an object? and i cant access its functions?

everything works fine on my local machine using apache 2.2 and php5.x

under my webhost aoache is 1.3 and php4.4

I read about chaining in php4 is not allowed s i did that and i was able to fix the problem. but this i cant get it to work.

Any Ideas?
#2

[eluser]coolfactor[/eluser]
Please try to use [ code ] tags around your code samples. It makes it easier to read.

This is not method chaining. It works just fine on php4.
Code:
$this->modelnameyouwant->function();

After loading the model, trying using var_dump() on it.

Code:
$this->load->model('modelfilename', 'modelnameyouwant');
var_dump($this->modelnameyouwant); // what does this display in the browser?

Also, it really helps if you use your real code, not pretend code. Even the slightest difference can be the cause of the problem, so show us exactly what you are using in your code.
#3

[eluser]n00bPhpCoder[/eluser]
im sorry okay here it is:

This one is for viewing the Comments

Code:
function View($id){
  $this->load->helper('url');
  $data['site_url']=base_url();  
  $this->load->model('postingsmodel','blog');
  $this->load->model('postingcommentsmodel','pc');  
  
  $data['article']=$this->blog->getEntries(10,ARTICLE_POST_TYPE);
  $query= $this->db->query("Select myquote,author from quotes order by rand() limit 1");
  $data['quotes']=$query->result();
  $data['site_url']=base_url();
  
  // Load Blog
  $data['blogs']=$this->blog->find($id);
    // Load Existing Comments
  $data['comments']=$this->pc->getEntries(30,$id);
  $this->load->view('comments',$data);
}

i created this one
Code:
class Vardump extends Controller {



function Vardump()
{
  parent::Controller();
}

function index()
{
  $this->load->model('postingsmodel','blog');
  echo var_dump($this->blog);
}
}

and it say object. Did i do something wrong on the code above? I think theyre pretty much the same
#4

[eluser]coolfactor[/eluser]
Ah, the problem may be the "View" function you defined. That would conflict with the ->load->view() method under PHP4.

Try renaming your function to something else to see if the problem goes away.
#5

[eluser]n00bPhpCoder[/eluser]
I see, maybe that was causing the problem. Okay i will try that. I should rename my functions to a more unique and meaningful ones Big Grin
#6

[eluser]n00bPhpCoder[/eluser]
Sir, that was causing the problems. I never it was a conflict on other reserved function for CI. Where learned a lot today. Big Grin Thanks

I wish everyone would be so patient to answer our questions though we are still a noob Smile




Theme © iAndrew 2016 - Forum software by © MyBB