Creating an object by primary key

edited December 2012 in Bug Reports
In the documentation the example for getting a record by primary key is:

$foo = $this->examples_model->find_by_key(1);
$foo->bar = 'This is a test';
$foo->save();

In the documentation the find_by_key method returns an array by default and not an object like above. In my code I tried this:

$p = $this->products_model->find_by_key(2, 'object');
$p->title = 'Changed title';
$p->save();

It does return an object, but doesn't inherit any of the functions like save() etc

My model is pretty simple, does anyone know what I'm doing wrong?

class Products_model extends Base_module_model {

function __construct()
{
parent::__construct('products', array('key_field' => 'id'));
}

}

Comments

  • edited 2:23PM
    You need to add a Product_model class to that Products_model class that extends "Base_module_record" like so:
    class Products_model extends Base_module_model { function __construct() { parent::__construct('products', array('key_field' => 'id')); } } class Product_model extends Base_module_record { }
  • edited 2:23PM
    That worked great thanks, really liking what Fuel offers, by far the best CMS I've used.
  • edited 2:23PM
    Welcome and thanks. If you are just starting out, I'd recommend checking out the 1.0 beta version if you haven't already which includes a lot of new features and bug fixes:
    https://github.com/daylightstudio/FUEL-CMS/tree/1.0
Sign In or Register to comment.