I’M newbie use grocery CRUD ...
it’s great plugin for CRUD, but I’Have problem with function set_model
in my model I use this code
<?php
class MAsset extends grocery_Model {
function __construct(){
parent::__construct();
}
function getAll(){
$this->db->select('nama,email');
$this->db->from('newsletter');
$this->db->limit(10);
$this->db->order_by('id_newslatter','ASC');
$query = $this->db->get();
return $query->result();
}
}
and in controller I use
$this->load->library('grocery_Exceptions');
try{
/* This is only for the autocompletion */
$crud = new grocery_CRUD();
//$crud->set_theme('datatables');
$this->load->model('MAsset');
$datase = $this->MAsset->getAll();
$crud->set_model($datase);
$crud->set_subject('NewsLetter');
$crud->required_fields('nama','email');
$crud->columns('nama','email');
$crud->render();
}catch(Exception $e){
$this->grocery_exceptions->show_error($e->getMessage(), $e->getTraceAsString());
}
Error in Output :
Fatal error: Class 'grocery_Model' not found in C:\XXXX\XXX\application\models\MAsset.php on line 2
How to Fix this problem ?
For your CRUD that you say you don’t need any model. Forgot the models. The set_model is for more complicated projects. For your example you can do it like this:
function my_newsletter(){
$crud = new grocery_CRUD();
$crud->order_by('id_newslatter','ASC');
$crud->set_table('newsletter');
$crud->set_subject('NewsLetter');
$crud->required_fields('nama','email');
$crud->columns('nama','email');
$crud->render();
}
It’s an easy codeigniter CRUD , no need of models, views, javascripts. It’s easier than you think. Read the documentation and the installation for codeigniter 2 and see the working examples.
Hope I help.
Now if you want to use models in the future for your reasons - you will do it like this:
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_model('MAsset');
$crud->set_subject('NewsLetter');
$crud->required_fields('nama','email');
$crud->columns('nama','email');
$crud->render();
and you MUST use your model by extending grocery_Model (That extends CI_Model) So if your model is something like this:
class MAsset extends CI_Model {
function __construct()
{
parent::__construct();
}
mpla mpla mpla….
}
Now it will be:
class MAsset extends grocery_Model {
//No need to have a contruct
function getAll(){
}
mpla mpla mpla….
}