Using session as var in grid controller Codeigniter

QuestionsUsing session as var in grid controller Codeigniter
C3media asked 7 years ago

Hello,

I need to save session user in virtual column of grid controller code:

Var:

$this->session->userdata('biller_id')

Code:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Segway extends MY_Controller
{

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

if (!$this->loggedIn) {
$this->session->set_userdata('requested_page', $this->uri->uri_string());
$this->sma->md('login');
}
if (!$this->Owner && !$this->Admin) {
$this->session->set_flashdata('warning', lang('access_denied'));
redirect($_SERVER["HTTP_REFERER"]);
}
}

public function show_grid()
{
$db_conf = array();
$db_conf["type"] = "mysqli"; // mysql,oci8(for oracle),mssql,postgres,sybase
$db_conf["server"] = "localhost";
$db_conf["user"] = "root";
$db_conf["password"] = "root";
$db_conf["database"] = "griddemo";

require_once("lib/inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);

$grid = array();
// set table for CRUD operations
$grid["caption"] = "Test CI GRID";
$grid["rowNum"] = 10;//10,15 — tinggi grid
$grid["shrinkToFit"] = true;
$grid["autowidth"] = true;
$grid["hidegrid"] = true;
//$grid["width"] = true;
$grid["height"] = 450;
#$grid["sortorder"] = "desc";
$grid["toolbar"] = "top";
$grid["add_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'750', 'top'=>'150', 'left'=>'200');
$grid["edit_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'750', 'top'=>'150', 'left'=>'200');
$grid["view_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'750', 'top'=>'150', 'left'=>'200');
$g->set_options($grid);

$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"view"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_excel"=>true, // show/hide export to excel option
"export_pdf"=>true,
"autofilter" => false, // show/hide autofilter for search – advance, false,true
"search" => false, // show single/multi field search condition (e.g. simple or advance)
"inlineedit" => true
)
);

// render grid
$g->select_command = "select * FROM country";
$g->table = "country";
$g->set_columns($cols);

$data['grid'] = $g->render("list1");
//$this->load->view('grilla',$data);
$this->load->view('default/views/show_grid',$data); // For circle 404 page

}

}

Thank you!

6 Answers
Abu Ghufran answered 7 years ago

You can define virtual column and set it as default value.
e.g.
$col["name"] = "biller";
$col["title"] = "Biller";
$col["editable"] = "Biller";
$col["editoptions"]["defaultValue"] = $this->session->userdata('biller_id')
….

C3media answered 7 years ago

Ok resolved,

Thank you!

C3media answered 7 years ago

Hello,

I get error 50 rendering individual column table names:

$col_cli = array();
$col_cli["title"] = "Id";
$col_cli["name"] = "id";
$col_cli["width"] = "20";
$col_cli["hidden"] = true;
$col_cli["show"] = array("add"=>true, "edit"=>true, "list"=>true);
$cols_cli[] = $col_cli;

$col_cli = array();
$col_cli["title"] = "Nombre";
$col_cli["name"] = "name";
$col_cli["width"] = "20";
$col_cli["editable"] = true;
$col_cli["editrules"] = array("required"=>true); // and is required
$col_cli["show"] = array("add"=>true, "edit"=>true, "list"=>true);
$cols_cli[] = $col_cli;

Error 500.

Thanks!

Abu Ghufran answered 7 years ago

Hi,

Please check error log and message that error details.
There could be many reasons for 500 error.

C3media answered 7 years ago

Debugging error get this:

inject.js – status 200

segway – status 500

https://diigo.com/0b9b48

Thank you!

Abu Ghufran answered 7 years ago

This is JS error in browser. You need to check server side php error log for 500 server error details.
Contact your hosting service for locating error log file.

Your Answer

0 + 15 =

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?