Skip to content

Instantly share code, notes, and snippets.

@gridphp
Last active August 9, 2021 22:58
Show Gist options
  • Save gridphp/857e8254d58d5f91fe43ca69bbd059d6 to your computer and use it in GitHub Desktop.
Save gridphp/857e8254d58d5f91fe43ca69bbd059d6 to your computer and use it in GitHub Desktop.
CodeIgniter 4 - Demo Controller Code (app/Controllers/Home.php, Line 9-28) & View Code (app/Views/welcome_message.php, line 234-244)
<?php
namespace App\Controllers;
class Home extends BaseController
{
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(ROOTPATH."public/lib/inc/jqgrid_dist.php");
$g = new \jqgrid($db_conf);
$grid = array();
// set table for CRUD operations
$grid["caption"] = "CodeIgniter Datagrid";
$g->set_options($grid);
// render grid
$g->table = "customers";
$data['grid'] = $g->render("list1");
return view('welcome_message',$data);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/base/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="lib/js/jquery.min.js" type="text/javascript"></script>
<script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>
<section>
<div style="margin:10px">
<?php echo $grid?>
</div>
</section>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment