datamapper or на codeigniter не работает

Добрый день всем. Я пробую DATAMAPPER ORM (мастер wan) на Codeigniter. Пример приложения работает нормально. Но когда я пытаюсь сделать свои собственные модели и контроллеры, это не работает. Все шаги по инструкции сделал. Вот код:

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);
}

}

Я создал таблицу в БД (блог с одной строкой, называемой контентом).

А вот и контроллер:

class Blog extends CI_Controller {

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

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

}

Но всегда выдает ошибку: Fatal error: Call to undefined method Blog::save() in C:\xampp\htdocs\wanwizarddatamapper\application\controllers\blog.php on line 29

Ууу меня это угнетает! Можешь мне помочь? Спасибо


person Tonino    schedule 15.09.2012    source источник
comment
Есть ли причина, по которой вам нужно использовать картограф данных? Если нет, я бы использовал обычные модели, используя класс активной записи CodeIgniter.   -  person seangates    schedule 18.09.2012


Ответы (1)


Я считаю, что у вас есть конфликт имен между вашей моделью и контроллером. Попробуйте переименовать свою модель в 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";
  }

}
person swatkins    schedule 11.10.2012