How to use model in codeigniter ?

QuestionsHow to use model in codeigniter ?
Abidou Omar asked 6 years ago

Hello Abu,

Can you give me on example of how to use model (MVC architecture) in codeigniter ?

 

4 Answers
Abu answered 6 years ago

Hi,

Demo may take little time. I can guide how to do it. In controller where you define grid object, you can also set:

        $e[“on_insert”] = array(“my_model_insert”, $model_user, false);
        $g->set_events($e);

Where my_model_insert is function of $model_user model object. 3rd argument of false tells grid not to execute it’s INSERT query and insert processing is done by callback function.

You may also need to return JSON object for grid on insert, update to reflect changes on grid.
https://phpgrid.org/demo/demos/editing/custom-events.phps (line 119)

Abidou answered 6 years ago

Thank you Mr Abu; In my controller   code : public function index() { $db_conf = array(); $db_conf[\”type\”] = \”mysqli\”; // mysql,oci8(for oracle),mssql,postgres,sybase $db_conf[\”server\”] = \”127.0.0.1\”; $db_conf[\”user\”] = \”root\”; $db_conf[\”password\”] = \”\”; $db_conf[\”database\”] = \”griddemo\”; require_once(\”assets/phpgrid/lib/inc/jqgrid_dist.php\”); $g = new jqgrid($db_conf); $grid = array(); // set table for CRUD operations $grid[\”caption\”] = \”Test CI GRID\”; $grid[\”rowNum\”] = 20;//10,15 — tinggi grid $grid[\”autowidth\”] = true; $grid[\”height\”] = 460; $grid[\”showhidecolumns\”]= true; $e[\”on_data_display\”] = array(\”filter_display\”, null, false); $grid->set_events($e);   $g->table = \”client\”; $g->set_options($grid); $data[\’grid\’] = $g->render(\”list1\”); $this->load->view(\’show_grid\’,$data); }   Mode code : function filter_display($data) { foreach($data[\”params\”] as &$d) { foreach($d as $k=>$v) $d[$k] = strtoupper($d[$k]); } }   I have error :   HTTP ERROR 500 null

Abidou answered 6 years ago

Thank you Mr Abu;

In my controller   code :

public function index()
{
$this->load->model(‘GridModel’);
require_once(“assets/phpgrid/lib/inc/jqgrid_dist.php”);
$g = new jqgrid($db_conf);

$grid = array();
// set table for CRUD operations
$grid[“caption”] = “Test CI GRID”;
$grid[“rowNum”] = 20;//10,15 — tinggi grid
$grid[“autowidth”] = true;
$grid[“height”] = 460;
$grid[“showhidecolumns”]= true;

$e[on_data_display”] = array(“filter_display”, $GridModel, false);
$grid->set_events($e);

$g->set_options($grid);

$g->table = “client”;
$data[‘grid’] = $g->render(“list1”);
$this->load->view(‘show_grid’,$data);
}

 

In model : GridModel.php

function filter_display($data)
{
foreach($data[“params”] as &$d)
{
foreach($d as $k=>$v)
$d[$k] = strtoupper($d[$k]);
}
}

I have error :   HTTP ERROR 500 null

Abidou answered 6 years ago

Can you give an example :

GridController.php

GridModel.php

Thanks.

 

Your Answer

11 + 12 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?