Welcome Guest, Not a member yet? Register   Sign In
Load view in custom frame
#1
Information 

Hello,


I have one page frame based in codeingniter, and need to load other view here; this is scenario example:
[Image: 2aihdfm.png]
This is Controller code:


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

class 
Notifications 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"]);
        }
        $this->lang->load('notifications'$this->Settings->user_language);
        $this->load->library('form_validation');
        $this->load->model('cmt_model');

    }

    function index()
    {
        if (!$this->Owner && !$this->Admin) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        $this->data['error'] = validation_errors() ? validation_errors() : $this->session->flashdata('error');
        $bc = array(array('link' => base_url(), 'page' => lang('home')), array('link' => '#''page' => lang('notifications')));
        $meta = array('page_title' => lang('notifications'), 'bc' => $bc);
        $this->page_construct('notifications/index'$meta$this->data);
    }

    function getNotifications()
    {

        $this->load->library('datatables');
        $this->datatables
            
->select("id, comment, date, from_date, till_date")
            ->from("notifications")
            //->where('notification', 1)
            ->add_column("Actions""<div class=\"text-center\"><a href='" site_url('notifications/edit/$1') . "' data-toggle='modal' data-target='#myModal' class='tip' title='" lang("edit_notification") . "'><i class=\"fa fa-edit\"></i></a> <a href='#' class='tip po' title='<b>" $this->lang->line("delete_notification") . "</b>' data-content=\"<p>" lang('r_u_sure') . "</p><a class='btn btn-danger po-delete' href='" site_url('notifications/delete/$1') . "'>" lang('i_m_sure') . "</a> <button class='btn po-close'>" lang('no') . "</button>\"  rel='popover'><i class=\"fa fa-trash-o\"></i></a></div>""id");
        $this->datatables->unset_column('id');
        echo $this->datatables->generate();
    }

    function add()
    {

        $this->form_validation->set_rules('comment'lang("comment"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->addNotification($data)) {
            $this->session->set_flashdata('message'lang("notification_added"));
            redirect("notifications");
        } else {

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'),
            );

            $this->data['error'] = validation_errors();
            $this->data['modal_js'] = $this->site->modal_js();
            $this->load->view($this->theme 'notifications/add'$this->data);

        }
    }

    function edit($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->input->post('id')) {
            $id $this->input->post('id');
        }

        $this->form_validation->set_rules('comment'lang("notifications"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->updateNotification($id$data)) {

            $this->session->set_flashdata('message'lang("notification_updated"));
            redirect("notifications");

        } else {

            $comment $this->cmt_model->getCommentByID($id);

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'$comment->comment),
            );


            $this->data['notification'] = $comment;
            $this->data['id'] = $id;
            $this->data['modal_js'] = $this->site->modal_js();
            $this->data['error'] = validation_errors();
            $this->load->view($this->theme 'notifications/edit'$this->data);

        }
    }

    function delete($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->cmt_model->deleteComment($id)) {
            $this->sma->send_json(array('error' => 0'msg' => lang("notifications_deleted")));
        }
    }



This is View code:


PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<script>
    $(document).ready(function () {
        oTable = $('#NTTable').dataTable({
            "aaSorting": [[1, "asc"], [2, "asc"]],
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "<?= lang('all'?>"]],
            "iDisplayLength": <?= $Settings->rows_per_page ?>,
            'bProcessing': true, 'bServerSide': true,
            'sAjaxSource': '<?= site_url('notifications/getNotifications'?>',
            'fnServerData': function (sSource, aoData, fnCallback) {
                aoData.push({
                    "name": "<?= $this->security->get_csrf_token_name() ?>",
                    "value": "<?= $this->security->get_csrf_hash() ?>"
                });
                $.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback});
            },
            "aoColumns": [null, {"mRender": fld}, {"mRender": fld}, {"mRender": fld}, {"bSortable": false}]
        });
    });
</script>

<div class="box">
    <div class="box-header">
        <h2 class="blue"><i class="fa-fw fa fa-info-circle"></i><?= lang('notifications'); ?></h2>

        <div class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown"><a href="<?= site_url('notifications/add'); ?>" data-toggle="modal"
                                        data-target="#myModal"><i class="icon fa fa-plus"></i></a></li>
            </ul>
        </div>
    </div>
    <div class="box-content">
        <div class="row">
            <div class="col-lg-12">

                <p class="introtext"><?= lang('list_results'); ?></p>

                <div class="table-responsive">
                    <table id="NTTable" cellpadding="0" cellspacing="0" border="0"
                           class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th><?php echo $this->lang->line("notification"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("submitted_at"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("from"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("till"); ?></th>
                            <th style="width:80px;"><?php echo $this->lang->line("actions"); ?></th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td colspan="5" class="dataTables_empty"><?= lang('loading_data_from_server'?></td>
                        </tr>

                        </tbody>
                    </table>
                </div>
                <!--<p><a href="<?php echo site_url('notifications/add'); ?>" class="btn btn-primary" data-toggle="modal" data-target="#myModal"><?php echo $this->lang->line("add_notification"); ?></a></p>-->
            </div>
        </div>
    </div>
</div> 

Then, as above I need to load this scenario in same frame:

[Image: 2i2c3lv.jpg]
This is Controller code:


PHP 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

}




And this is View code:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid page 1</title>
</head>
<body>

<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="<?php echo base_url() ?>lib/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<div class="box">
<?php echo $grid ?>
</div>
</body>
</html> 


It's working, but not load in same frame as first scenario, thank you!
Reply
#2
Smile 
(This post was last modified: 01-16-2018, 12:40 PM by c3media.)

Hello,


I have one page frame based in codeingniter, and need to load other view here; this is scenario example:
[Image: 2aihdfm.png]
This is Controller code:


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

class 
Notifications 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"]);
        }
        $this->lang->load('notifications'$this->Settings->user_language);
        $this->load->library('form_validation');
        $this->load->model('cmt_model');

    }

    function index()
    {
        if (!$this->Owner && !$this->Admin) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        $this->data['error'] = validation_errors() ? validation_errors() : $this->session->flashdata('error');
        $bc = array(array('link' => base_url(), 'page' => lang('home')), array('link' => '#''page' => lang('notifications')));
        $meta = array('page_title' => lang('notifications'), 'bc' => $bc);
        $this->page_construct('notifications/index'$meta$this->data);
    }

    function getNotifications()
    {

        $this->load->library('datatables');
        $this->datatables
            
->select("id, comment, date, from_date, till_date")
            ->from("notifications")
            //->where('notification', 1)
            ->add_column("Actions""<div class=\"text-center\"><a href='" site_url('notifications/edit/$1') . "' data-toggle='modal' data-target='#myModal' class='tip' title='" lang("edit_notification") . "'><i class=\"fa fa-edit\"></i></a> <a href='#' class='tip po' title='<b>" $this->lang->line("delete_notification") . "</b>' data-content=\"<p>" lang('r_u_sure') . "</p><a class='btn btn-danger po-delete' href='" site_url('notifications/delete/$1') . "'>" lang('i_m_sure') . "</a> <button class='btn po-close'>" lang('no') . "</button>\"  rel='popover'><i class=\"fa fa-trash-o\"></i></a></div>""id");
        $this->datatables->unset_column('id');
        echo $this->datatables->generate();
    }

    function add()
    {

        $this->form_validation->set_rules('comment'lang("comment"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->addNotification($data)) {
            $this->session->set_flashdata('message'lang("notification_added"));
            redirect("notifications");
        } else {

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'),
            );

            $this->data['error'] = validation_errors();
            $this->data['modal_js'] = $this->site->modal_js();
            $this->load->view($this->theme 'notifications/add'$this->data);

        }
    }

    function edit($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->input->post('id')) {
            $id $this->input->post('id');
        }

        $this->form_validation->set_rules('comment'lang("notifications"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->updateNotification($id$data)) {

            $this->session->set_flashdata('message'lang("notification_updated"));
            redirect("notifications");

        } else {

            $comment $this->cmt_model->getCommentByID($id);

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'$comment->comment),
            );


            $this->data['notification'] = $comment;
            $this->data['id'] = $id;
            $this->data['modal_js'] = $this->site->modal_js();
            $this->data['error'] = validation_errors();
            $this->load->view($this->theme 'notifications/edit'$this->data);

        }
    }

    function delete($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->cmt_model->deleteComment($id)) {
            $this->sma->send_json(array('error' => 0'msg' => lang("notifications_deleted")));
        }
    }



This is View code:


PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<script>
    $(document).ready(function () {
        oTable = $('#NTTable').dataTable({
            "aaSorting": [[1, "asc"], [2, "asc"]],
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "<?= lang('all'?>"]],
            "iDisplayLength": <?= $Settings->rows_per_page ?>,
            'bProcessing': true, 'bServerSide': true,
            'sAjaxSource': '<?= site_url('notifications/getNotifications'?>',
            'fnServerData': function (sSource, aoData, fnCallback) {
                aoData.push({
                    "name": "<?= $this->security->get_csrf_token_name() ?>",
                    "value": "<?= $this->security->get_csrf_hash() ?>"
                });
                $.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback});
            },
            "aoColumns": [null, {"mRender": fld}, {"mRender": fld}, {"mRender": fld}, {"bSortable": false}]
        });
    });
</script>

<div class="box">
    <div class="box-header">
        <h2 class="blue"><i class="fa-fw fa fa-info-circle"></i><?= lang('notifications'); ?></h2>

        <div class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown"><a href="<?= site_url('notifications/add'); ?>" data-toggle="modal"
                                        data-target="#myModal"><i class="icon fa fa-plus"></i></a></li>
            </ul>
        </div>
    </div>
    <div class="box-content">
        <div class="row">
            <div class="col-lg-12">

                <p class="introtext"><?= lang('list_results'); ?></p>

                <div class="table-responsive">
                    <table id="NTTable" cellpadding="0" cellspacing="0" border="0"
                           class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th><?php echo $this->lang->line("notification"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("submitted_at"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("from"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("till"); ?></th>
                            <th style="width:80px;"><?php echo $this->lang->line("actions"); ?></th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td colspan="5" class="dataTables_empty"><?= lang('loading_data_from_server'?></td>
                        </tr>

                        </tbody>
                    </table>
                </div>
                <!--<p><a href="<?php echo site_url('notifications/add'); ?>" class="btn btn-primary" data-toggle="modal" data-target="#myModal"><?php echo $this->lang->line("add_notification"); ?></a></p>-->
            </div>
        </div>
    </div>
</div> 

Then, as above I need to load this scenario in same frame:

[Image: 2i2c3lv.jpg]
This is Controller code:


PHP 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

}




And this is View code:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid page 1</title>
</head>
<body>

<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="<?php echo base_url() ?>lib/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<div class="box">
<?php echo $grid ?>
</div>
</body>
</html> 


It's working, but not load in same frame as first scenario, thank you!
[/quote]
Reply
#3

(01-15-2018, 07:55 PM)c3media Wrote: Hello,


I have one page frame based in codeingniter, and need to load other view here; this is scenario example:
[Image: 2aihdfm.png]
This is Controller code:


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

class 
Notifications 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"]);
        }
        $this->lang->load('notifications'$this->Settings->user_language);
        $this->load->library('form_validation');
        $this->load->model('cmt_model');

    }

    function index()
    {
        if (!$this->Owner && !$this->Admin) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        $this->data['error'] = validation_errors() ? validation_errors() : $this->session->flashdata('error');
        $bc = array(array('link' => base_url(), 'page' => lang('home')), array('link' => '#''page' => lang('notifications')));
        $meta = array('page_title' => lang('notifications'), 'bc' => $bc);
        $this->page_construct('notifications/index'$meta$this->data);
    }

    function getNotifications()
    {

        $this->load->library('datatables');
        $this->datatables
            
->select("id, comment, date, from_date, till_date")
            ->from("notifications")
            //->where('notification', 1)
            ->add_column("Actions""<div class=\"text-center\"><a href='" site_url('notifications/edit/$1') . "' data-toggle='modal' data-target='#myModal' class='tip' title='" lang("edit_notification") . "'><i class=\"fa fa-edit\"></i></a> <a href='#' class='tip po' title='<b>" $this->lang->line("delete_notification") . "</b>' data-content=\"<p>" lang('r_u_sure') . "</p><a class='btn btn-danger po-delete' href='" site_url('notifications/delete/$1') . "'>" lang('i_m_sure') . "</a> <button class='btn po-close'>" lang('no') . "</button>\"  rel='popover'><i class=\"fa fa-trash-o\"></i></a></div>""id");
        $this->datatables->unset_column('id');
        echo $this->datatables->generate();
    }

    function add()
    {

        $this->form_validation->set_rules('comment'lang("comment"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->addNotification($data)) {
            $this->session->set_flashdata('message'lang("notification_added"));
            redirect("notifications");
        } else {

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'),
            );

            $this->data['error'] = validation_errors();
            $this->data['modal_js'] = $this->site->modal_js();
            $this->load->view($this->theme 'notifications/add'$this->data);

        }
    }

    function edit($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->input->post('id')) {
            $id $this->input->post('id');
        }

        $this->form_validation->set_rules('comment'lang("notifications"), 'required|min_length[3]');

        if ($this->form_validation->run() == true) {
            $data = array(
                'comment' => $this->input->post('comment'),
                'from_date' => $this->input->post('from_date') ? $this->sma->fld($this->input->post('from_date')) : NULL,
                'till_date' => $this->input->post('to_date') ? $this->sma->fld($this->input->post('to_date')) : NULL,
                'scope' => $this->input->post('scope'),
            );
        } elseif ($this->input->post('submit')) {
            $this->session->set_flashdata('error'validation_errors());
            redirect("notifications");
        }

        if ($this->form_validation->run() == true && $this->cmt_model->updateNotification($id$data)) {

            $this->session->set_flashdata('message'lang("notification_updated"));
            redirect("notifications");

        } else {

            $comment $this->cmt_model->getCommentByID($id);

            $this->data['comment'] = array('name' => 'comment',
                'id' => 'comment',
                'type' => 'textarea',
                'class' => 'form-control',
                'required' => 'required',
                'value' => $this->form_validation->set_value('comment'$comment->comment),
            );


            $this->data['notification'] = $comment;
            $this->data['id'] = $id;
            $this->data['modal_js'] = $this->site->modal_js();
            $this->data['error'] = validation_errors();
            $this->load->view($this->theme 'notifications/edit'$this->data);

        }
    }

    function delete($id NULL)
    {
        if (!$this->Owner) {
            $this->session->set_flashdata('warning'lang('access_denied'));
            redirect($_SERVER["HTTP_REFERER"]);
        }

        if ($this->cmt_model->deleteComment($id)) {
            $this->sma->send_json(array('error' => 0'msg' => lang("notifications_deleted")));
        }
    }



This is View code:


PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<script>
    $(document).ready(function () {
        oTable = $('#NTTable').dataTable({
            "aaSorting": [[1, "asc"], [2, "asc"]],
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "<?= lang('all'?>"]],
            "iDisplayLength": <?= $Settings->rows_per_page ?>,
            'bProcessing': true, 'bServerSide': true,
            'sAjaxSource': '<?= site_url('notifications/getNotifications'?>',
            'fnServerData': function (sSource, aoData, fnCallback) {
                aoData.push({
                    "name": "<?= $this->security->get_csrf_token_name() ?>",
                    "value": "<?= $this->security->get_csrf_hash() ?>"
                });
                $.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback});
            },
            "aoColumns": [null, {"mRender": fld}, {"mRender": fld}, {"mRender": fld}, {"bSortable": false}]
        });
    });
</script>

<div class="box">
    <div class="box-header">
        <h2 class="blue"><i class="fa-fw fa fa-info-circle"></i><?= lang('notifications'); ?></h2>

        <div class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown"><a href="<?= site_url('notifications/add'); ?>" data-toggle="modal"
                                        data-target="#myModal"><i class="icon fa fa-plus"></i></a></li>
            </ul>
        </div>
    </div>
    <div class="box-content">
        <div class="row">
            <div class="col-lg-12">

                <p class="introtext"><?= lang('list_results'); ?></p>

                <div class="table-responsive">
                    <table id="NTTable" cellpadding="0" cellspacing="0" border="0"
                           class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th><?php echo $this->lang->line("notification"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("submitted_at"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("from"); ?></th>
                            <th style="width: 140px;"><?php echo $this->lang->line("till"); ?></th>
                            <th style="width:80px;"><?php echo $this->lang->line("actions"); ?></th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td colspan="5" class="dataTables_empty"><?= lang('loading_data_from_server'?></td>
                        </tr>

                        </tbody>
                    </table>
                </div>
                <!--<p><a href="<?php echo site_url('notifications/add'); ?>" class="btn btn-primary" data-toggle="modal" data-target="#myModal"><?php echo $this->lang->line("add_notification"); ?></a></p>-->
            </div>
        </div>
    </div>
</div> 

Then, as above I need to load this scenario in same frame:

[Image: 2i2c3lv.jpg]
This is Controller code:


PHP 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

}




And this is View code:


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid page 1</title>
</head>
<body>

<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url() ?>lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="<?php echo base_url() ?>lib/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<div class="box">
<?php echo $grid ?>
</div>
</body>
</html> 


It's working, but not load in same frame as first scenario, thank you!

I have resolved it, now would like to use $this->session->userdata('biller_id') as var in grid controller code, this is it:

<?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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB