Closed zoe-edwards closed 12 years ago
Yes, this is confusing.
namespace Model;
use DB;
class Users extends \Model
{
public static function create($pairs)
{
return DB::insert('users')->set($pairs)->execute();
}
}
or alternatively
class Model_Users extends \Model
{
public static function create($pairs)
{
return \DB::insert('users')->set($pairs)->execute();
}
}
[edited by Jelmer: take DB from global, not Fuel\Core\DB and you forgot the backslash prefix in the second example.]
I'm sorry guys, but this is REALLY basic namespaces stuff in PHP - the For Noobs section. Prefix a backslash to take classes from global instead of the current namespace: http://nl.php.net/manual/en/language.namespaces.basics.php#example-225
The documentation is confusing for beginners of fuel.
http://www.fuelphp.com/dev-docs/general/models.html at least it is below, isn't it?
namespace Model;
class Welcome extends \Model {
public static function get_results()
{
// Database interactions
}
}
Ah, I didn't see it was actually missing in the examples. Though understanding this type of error should still be common knowledge. I added a note about it, but I can't promise it'll stay - it's about the most basic mistake one can make when using namespaces.
[edit] Just to clarify: Fuel docs shouldn't do a namespaces 101, anyone who doesn't have a clue about them should use the php.net docs - we're not here to teach basic PHP.
On the Models page, the instructions for creating a Model are as such:
Which I’ve used in a Model I’ve made like so:
First error is
ErrorException [ Error ]: Class 'Model\Model' not found
which is reasonable, as I haven’t created a Model class to extend from. So I remove that line.Then I get
ErrorException [ Error ]: Class 'Model\DB' not found
referring to the line callingDB::insert
. That seems reasonable, because I’m in the Model namespace? But obviously I remove that, then the Controller can’t find the Model.I’m not sure what the correct way of managing it is?
Using 1.1 RC1