1
votes

Good day to all. I am trying DATAMAPPER ORM (wan wizard) on Codeigniter. Example aplication works fine. But when I try make my own models and controllers it doesn't work. I did every step in the instruction. Here is a code:

class Blog extends DataMapper {

var $has_one = array();
var $has_many = array();
var $validation = array(
    'content' => array(
        // example is required, and cannot be more than 120 characters long.
        'rules' => array('required', 'max_length' => 255),
        'label' => 'Content'
    )
);
function __construct($id = NULL)
{
    parent::__construct($id);
}

}

I created table in db (blog with one row called content).

And here is a controller:

class Blog extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $blog = new Blog;
        $blog->content = "shaa";
        $blog->save();
        echo "done";
    }

}

But it always gives me an error: Fatal error: Call to undefined method Blog::save() in C:\xampp\htdocs\wanwizarddatamapper\application\controllers\blog.php on line 29

Uuhh it's depresing me! Can you help me? Thank you

1
Is there a reason you need to use a data mapper? If not, I would use the regular models using the CodeIgniter active record class. - seangates

1 Answers

1
votes

I believe you have a naming conflict between your model and controller. Try renaming your model to BlogEntry:

class BlogEntry extends DataMapper {

  var $has_one = array();
  var $has_many = array();
  var $validation = array(
    'content' => array(
      // example is required, and cannot be more than 120 characters long.
      'rules' => array('required', 'max_length' => 255),
      'label' => 'Content'
    )
  );
  function __construct($id = NULL)
  {
    parent::__construct($id);
  }

}

class Blog extends CI_Controller {

  function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $blogentry = new BlogEntry;
    $blogentry->content = "shaa";
    $blogentry->save();
    echo "done";
  }

}