Call to a member function on a non-object
Permalink
Hey!
So I'm trying my first big PHP project built from the ground up. I've been looking at a ton of controllers, models and etc so I thought I'd take a stab at it and failed....a lot. *sighs* I am calling the model from a single page. Here's the code:
Model Code:
Single-page code
And I get....
Appreciate any tips! Thanks!
So I'm trying my first big PHP project built from the ground up. I've been looking at a ton of controllers, models and etc so I thought I'd take a stab at it and failed....a lot. *sighs* I am calling the model from a single page. Here's the code:
Model Code:
Single-page code
$cert = Loader::model('certification'); echo "SQL: ".$cert->getSubmitted("hello");
And I get....
Call to a member function getSubmitted() on a non-object
Appreciate any tips! Thanks!
PS. There are a few required patterns of c5 class and file naming conventions that may also come into play if you get more complicated.
Hey JohntheFish!
I tried that once too and got the following error (view attached). I'm supposed to make a table in the db?
I tried that once too and got the following error (view attached). I'm supposed to make a table in the db?
you should place model in /models folder and filename should be in lowercase .your modelname should be certification.php .so your file structure should be /models/certification.php
I got that far. It isn't throwing that kind of error. It was before anyway. ;)
Thank you thank you for your tips!
Thank you thank you for your tips!
Looking at it again, I think the core class Model is designed to be used deep inside database stuff. The 'models' I have created do not extend the core Model, but do their own thing or inherit from Object.
So in the case of your minimal example, try:
Or:
So in the case of your minimal example, try:
class Certification { ... }
Or:
class Certification extends Object { ... }
Ahhh gotcha. That makes sense! :) I'll try that angle. Thanks!
What you have done would work for a helper( where an instance is returned by Loader::helper), but for everything else, you have to create your own instance.