การเรียกใช้ฟังก์ชั่นแสดงรายงานแนวนอน แสดงผลรวมผู้ใช้บริการ แยกตามประเภท

โดย SONGCHAI SAETERN
การเรียกใช้ฟังก์ชั่นแสดงรายงานแนวนอน แสดงผลรวมผู้ใช้บริการ แยกตามประเภท



มาดูขั้นตอนการเรียกใช้งานฟังก์ชั่นกันแบบทีละขั้นตอนกันครับ






ส่วนของ Model

        public function report_summary($begin_date, $final_date)
{
$begin_date = setDateToStandard($begin_date);
$final_date = setDateToStandard($final_date);
//SET data list
$left_join = "LEFT JOIN group_enrolment ON enrolment.Enrolment_id = group_enrolment.Enrolment_id";
$where_search = "WHERE begin_date >= '$begin_date' AND final_date <= '$final_date'";

//Group data by vertical_id and horizontal_id
$summary_config = array(
'table_name' => 'enrolment',
'vertical_id' => 'enrolment.Enrolment_id', 
'vertical_name' => 'enrolment.organization',
'horizontal_id' => 'group_enrolment.`type`', 
'summary_field' => 'group_enrolment.num', 
'other_select' => 'enrolment.begin_date', 
'join_condition' => $left_join, 
'where_condition' => $where_search
);
$this->summary = $summary_config;
//SET thead list
$thead_config = array(
'table' => 'type', 
'id' => 'type_id', 
'name' => 'type_name'
);
$this->summary_hor = $thead_config;
//
$data = $this->summary_group_hor();
return $data;
}


ส่วนของ Controller

        public function report_summary()
{
$this->breadcrumb_data['breadcrumb'] = array(
array('title' => 'Enrolment', 'url' => site_url('ice_siep/enrolment')),
array('title' => 'สรุป', 'url' => '#', 'class' => 'active')
);
$begin_date = $this->input->post('begin_date', TRUE);
$final_date = $this->input->post('final_date', TRUE);
if($begin_date == ''){
$begin_date = '01/'. date('m') . '/'. (date('Y') + 543);
}
if($final_date == ''){
$final_date = date('t'). '/' . date('m') . '/'. (date('Y') + 543);
}
$summary = $this->Enrolment->report_summary($begin_date, $final_date);
$this->data['colspan'] = $summary['colspan'];
$this->data['thead_list'] = $summary['thead_list'];
$this->data['data_list'] = $summary['data_list'];
$this->data['sum_column'] = $summary['sum_column'];
$this->data['grand_total'] = $summary['grand_total'];
$this->data['begin_date'] = $begin_date;
$this->data['final_date'] = $final_date;
$this->render_view('ice_siep/enrolment/report_summary');
}

ส่วนของ View


                        <table class="table table-bordered table-striped table-hover">
<thead class="info">
<tr bgcolor="#eeeeee">
<th rowspan="2">วันที่</th>
<th rowspan="2">สถาบัน / หน่วยงาน</th>
<th colspan="{colspan}" class="text-center">ผู้มาใช้บริการแบบกลุ่ม</th>
<th rowspan="2">รวม</th>
</tr>
<tr bgcolor="#dddddd">
{thead_list}
</tr>
</thead>
<tbody>
<tr parser-repeat="[data_list]">
<td>{begin_date}</td>
<td>{organization}</td>
{sum_td_list}
<td>{sub_total}</td>
</tr>
<tr>
<td colspan="2">รวม</td>
{sum_column}
<td>{grand_total}</td>
</tr>
</tbody>
</table>




วิธีเพิ่มคอมม่าหลักพัน และเปลี่ยนช่องว่าเป็น 0






ดูตัวอย่างเพิ่มเติม และคู่มือฉบับเต็มได้ที่
https://phpcodemania.blogspot.com/p/php-ci-mania.html#fqa






PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม
http://fastcoding.phpcodemania.com

ปรับแต่งเทมเพลต SB Admin 2 สำหรับใช้กับโปรเจ็กต์ Coffee Shop - PHP CI MANIA

โดย SONGCHAI SAETERN
ปรับแต่งเทมเพลต SB Admin 2 เพื่อใช้งานกับโปรเจ็กต์บริหารจัดการธุรกิจร้านกาแฟ

ดาวน์โหลดเทมเพลตสำหรับ PHP CI MANIA ได้ที่
https://github.com/sunzandesign/codeigniter_bootstrap_themes

ระบบบริหารจัดการธุรกิจร้านกาแฟ ตอนที่ 1



ติดตามบนยูทูปได้ที่ ระบบบริหารจัดการธุรกิจร้านกาแฟ - PHP CI MANIA


--------------------------------------------------------------


PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

CodeIgniter กับ Excel, PDF, Chart สร้างรายงานแผนภูมิ ส่งออก Excel สั่งพิมพ์ PDF บนระบบ PHP CI MANIA

โดย SONGCHAI SAETERN
การใช้งานไลบรารี่ PHPExcel, TCPDF, Chart.js สำหรับ PHP CI MANIA เวอร์ชั่น PREMIUM



เมื่อคลิกที่ปุ่มจะได้ผลลัพธ์แต่ละส่วนดังนี้


PHPExcel


TCPDF


Chart.js



ดูวิดีโอสาธิตการใช้งานแต่ละส่วนได้ที่นี่










PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

CodeIgniter กับการเรียกใช้งาน Chart.js สร้างรายงานแผนภูมิ ในโปรแกรม PHP CI MANIA

โดย SONGCHAI SAETERN
การนำข้อมูลจาก MySQL มาแสดงในรูปแบบแผนภูมิด้วย Chart.js



1. สร้างลิงค์เพื่อเรียกไปยังหน้า Controller ที่เตรียมไว้สำหรับแสดงข้อมูลเป็นไฟล์ PDFในที่นี้จะสร้างไปที่หน้าค้นหาและแสดงรายการ list_view.php (กรณีที่ต้องการแสดงในหน้าค้นหาและแสดงรายการ ก็สามารถเขียนโค้ดแทรกลงไปที่ list_view.php ได้เลย ไม่ต้องสร้างลิงค์ไปหน้าอื่น)

<div class="col-sm-12 col-md-12">
<div class="pull-right text-right">
<a href="{page_url}/export_excel" class="btn btn-success btn-lg" data-toggle="tooltip" title="ส่งออกข้อมูล">
<i class="fas fa-file-excel"></i></span> Excel
</a>
<a href="{page_url}/print_pdf" target="_blank" class="btn btn-danger btn-lg" data-toggle="tooltip" title="พิมพ์ข้อมูล">
<i class="fas fa-file-pdf"></i></span> PDF
</a>
<a href="{page_url}/report_chart" target="_blank" class="btn btn-info btn-lg" data-toggle="tooltip" title="รายงานกราฟ">
<i class="fas fa-chart-bar"></i></span> Chart
</a>
</div>
</div>


2. ในส่วนของ Controller ให้เรียกใช้ Model สำหรับดึงข้อมูลมาแสดง หรือสร้างคำสั่งชั่วคราวเพื่อดึงข้อมูลมาจากฐานข้อมูล MySQL และส่งข้อมูลไปยัง Views ที่เตรียมไว้

// create chart
    public function report_chart()
{
//ดึงข้อมูลจากฐานข้อมูล
$this->db->select("IF(sex=1,'ชาย','หญิง') AS sex, COUNT(sex) AS amount", FALSE);
$this->db->group_by("sex");
$query = $this->db->get('tb_student');
$student_summary = $query->result_array();
//จัดรูปแบบข้อมูล ยกระหว่าง TITLE / VALUES
$type_name = array_column($student_summary, 'sex');
$amount = array_column($student_summary, 'amount');
$this->data['student_summary_type'] = json_encode($type_name);
$this->data['student_summary'] = json_encode($amount);
$this->parser->parse('demo/student/report_chart', $this->data);
}

3. เพิ่มไฟล์ report_chart.php ซึ่งเป็นส่วนของ Views เพื่อทดสอบการแสดงผล
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Charts</title>
<link href="{base_url}assets/themes/sb-admin-bs4/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap core CSS-->
<link href="{base_url}/assets/module/chart.js/Chart.css" rel="stylesheet">
</head>
<body id="page-top">
<div id="content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-chart-pie"></i>
สถิตินักเรียน</div>
<div class="card-body">
<canvas id="myPieChart" width="100" height="100"></canvas>
</div>
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- Page level plugin JavaScript-->
<script src="{base_url}/assets/module/chart.js/Chart.bundle.js"></script>
<script>
// Set new default font family and font color to mimic Bootstrap's default styling
Chart.defaults.global.defaultFontFamily = '-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif';
Chart.defaults.global.defaultFontColor = '#292b2c';
// Pie Chart Example
var ctx = document.getElementById("myPieChart");
var myPieChart = new Chart(ctx, {
type: 'pie',
data: {
labels: {student_summary_type},
datasets: [{
data: {student_summary},
backgroundColor: ['#007bff', '#dc3545', '#ffc107'],
}],
},
});
</script>
</body>
</html>   


สังเกตส่วนที่ใช้รับค่าจาก Controller ก็คือตัวแปรที่อยู่ในวงเล็บปีกกา
{student_summary_type}
{student_summary}


4. จะได้ผลลัพธ์ดังนี้





PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

CodeIgniter กับการเรียกใช้งาน TCPDF สร้างรายงาน PDF ในโปรแกรม PHP CI MANIA

โดย SONGCHAI SAETERN
การสั่งพิมพ์รายงานแบบ PDF


1. สร้างลิงค์เพื่อเรียกไปยังหน้า Controller ที่เตรียมไว้สำหรับแสดงข้อมูลเป็นไฟล์ PDFในที่นี้จะสร้างไปที่หน้าค้นหาและแสดงรายการ list_view.php

<div class="col-sm-12 col-md-12">
<div class="pull-right text-right">
<a href="{page_url}/print_pdf" target="_blank" class="btn btn-danger btn-lg" data-toggle="tooltip" title="พิมพ์ข้อมูล">
<i class="fas fa-file-excel"></i></span> PDF
</a>
<a href="{page_url}/export_excel" class="btn btn-success btn-lg" data-toggle="tooltip" title="ส่งออกข้อมูล">
<i class="fas fa-file-excel"></i></span> Excel
</a>
</div>
</div>


2. สร้างไฟล์ Pdf.php ไว้ที่ application/libraries/ ซึ่งจะเรียกไลบรารี่ที่เราดาวน์โหลดเก็บไว้ใน application/third_party มาใช้อีกทีหนึ่ง (ดาวน์โหลดไลบรารี่ที่เกี่ยวข้องได้ที่ https://github.com/sunzandesign/PHP_CI_MANIA_Libraries)

<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
require_once APPPATH."/third_party/tcpdf/tcpdf.php";
class Pdf extends TCPDF{
    public function __construct(){
        parent::__construct();
    }
}

3. ในส่วนของ Controller ให้โหลดไลบรารี่ที่สร้างไว้มาใช้งาน
public function print_pdf()
{
// load excel library
         $this->load->library('Pdf');
$results = $this->Student->read(0, 1000);
$data_lists = $this->setDataListFormat($results['list_data'], 0);
$pdf = new Pdf('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
$font = 'thsarabun';
$pdf->font = $font;
$pdf->SetCreator("");
$pdf->SetAuthor("");
$pdf->SetTitle("รายงานทะเบียนนักเรียน");
$pdf->SetSubject("รายงานทะเบียนนักเรียน");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins(10, 10, 10);
$pdf->SetHeaderMargin(0);
$pdf->SetTopMargin(15);
$pdf->SetFooterMargin(0);
$pdf->SetFont($font, '', 16);
// Add a page
$pdf->AddPage("P");
$data['data_list'] = $data_lists;
$html = $this->parser->parse_repeat('demo/student/list_pdf', $data, true);
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
$pdf->lastPage();
$pdf->Output('Student_list.pdf', 'I');
}


4. เพิ่มไฟล์ list_pdf.php ซึ่งเป็นส่วนของ Views คล้ายกับหน้าค้นหาและแสดงผล แต่จะตัดเอาเฉพาะส่วนที่เราต้องการพิมพ์เท่านั้น เช่น ข้อมูลใน TABLE เท่านั้น
<style>
body {
font-family: 'TH SarabunPSK';
font-size : 16pt;
margin : 0px;
}
table{
width : 100%;
border-collapse: collapse;
}
table { page-break-inside:auto; }
th {
   background-color:lightgrey;
   text-align : center;
}
</style>
<h3 class="card-title"><i class="fa fa-list-alt"></i> ตารางแสดงรายการ ข้อมูล<b>นักเรียน</b></h3>
<table border="0.1" cellpadding="2">
<thead class="info">
<tr bgcolor="#dddddd">
<th width="20px;">#</th>
<th>id</th>
<th>รหัสประจำตัว</th>
<th>คำนำหน้าชื่อ</th>
<th>ชื่อ</th>
<th>นามสกุล</th>
<th>เพศ</th>
</tr>
</thead>
<tbody>
<tr parser-repeat="[data_list]" id="row_{record_number}">
<td  width="20px;">[{record_number}]</td>
<td>{id}</td>
<td>{student_code}</td>
<td>{preview_prefix_name}</td>
<td>{firstname}</td>
<td>{lastname}</td>
<td>{preview_sex}</td>
</tr>
</tbody>
</table>


5. เมื่อคลิกปุ่ม PDF ก็จะเปิดไปที่หน้า Controller ที่เตรียมไว้และแสดงข้อมูล






PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม
http://fastcoding.phpcodemania.com

CodeIgniter กับการเรียกใช้งาน PHPExcel ในโปรแกรม PHP CI MANIA

โดย SONGCHAI SAETERN
การส่งข้อมูลออกเป็นไฟล์ Excel



1. สร้างไฟล์ Excel.php ไว้ที่ application/libraries/ ซึ่งจะเรียกไลบรารี่ที่เราดาวน์โหลดเก็บไว้ใน application/third_party มาใช้อีกทีหนึ่ง (ดาวน์โหลดไลบรารี่ที่เกี่ยวข้องได้ที่ https://github.com/sunzandesign/PHP_CI_MANIA_Libraries)

<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
require_once APPPATH."/third_party/PHPExcel.php";
class Excel extends PHPExcel{

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


2. ในส่วนของ Controller ให้โหลดไลบรารี่ที่สร้างไว้มาใช้งาน


    public function export_excel()
{
        // load excel library
        $this->load->library('Excel');
$results = $this->Student->read(0, 1000);//1000 คือจำนวนข้อมูลที่ต้องการสูงสุด
$data_lists = $this->setDataListFormat($results['list_data'], 0);
        $objPHPExcel = new PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0);
     
   // set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'รหัสประจำตัว');
        $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'ชื่อ-นามสกุล');
        $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'เพศ');
// set header bold
$objPHPExcel->getActiveSheet()->getStyle("A1:C1")->getFont()->setBold( true );
        // set Row
        $rowCount = 2;
        foreach ($data_lists as $row) {
$objPHPExcel->getActiveSheet()
->setCellValueExplicit('A' . $rowCount, $row['student_code'], PHPExcel_Cell_DataType::TYPE_STRING);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $row['preview_prefix_name'].$row['firstname'].' '.$row['lastname']);
            $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $row['preview_sex']);
            $rowCount++;
        }
// auto size
foreach(range('A','C') as $columnID) {
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)
->setAutoSize(true);
}
        $filename = "student_". date("Y-m-d-H-i-s").".xlsx";
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
    }


3. สร้างลิงค์เพื่อเรียกไปยังหน้า Controller ที่เตรียมไว้สำหรับ Export ข้อมูลเป็นไฟล์ Excel ในที่นี้จะสร้างไปที่หน้าค้นหาและแสดงรายการ list_view.php

<div class="col-sm-12 col-md-12">
<div class="pull-right text-right">
<a href="{page_url}/print_pdf" target="_blank" class="btn btn-danger btn-lg" data-toggle="tooltip" title="พิมพ์ข้อมูล">
<i class="fas fa-file-excel"></i></span> PDF
</a>
<a href="{page_url}/export_excel" class="btn btn-success btn-lg" data-toggle="tooltip" title="ส่งออกข้อมูล">
<i class="fas fa-file-excel"></i></span> Excel
</a>
</div>
</div>


4. เมื่อคลิกปุ่ม Excel ก็จะเปิดไปที่หน้า Controller ที่เตรียมไว้ และเมื่อทำงานปกติก็จะมีป๊อบอัพดาวน์โหลดไฟล์แสดงขึ้นมา


5. เมื่อดาวน์โหลด/เปิดไฟล์ขึ้นมา จะพบข้อมูลตามที่กำหนดไว้ใน Controller








PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

PHP กับวิธีรับค่าพารามิเตอร์ GET จาก url ให้ครบถ้วน ก่อน Redirect ไปยังหน้าอื่น

โดย SONGCHAI SAETERN
หลายๆครั้งที่เราค้นหาคำสั่งหรือฟังก์ชั่นที่ PHP มีให้ไม่เจอ ก็ต้องพยายามเขียนฟังก์ชั่นขึ้นมาเอง


http_build_query()

ฟังก์ชั่นนี้ก็เช่นกัน ถ้าหาไม่เจอก็คงต้องเขียนขึ้นเองตามเคย


$other_param = $_GET;
unset($other_param['url']);

$url = isset($_GET['url']) ? urldecode($_GET['url']) : '';
$url .= '&'. http_build_query($other_param);

คำสั่งด้านบนนี้คือการรับค่าสำหรับ redirect ไปยังหน้าอื่น แต่พอดีว่าต้องพ่วงค่า $_GET ตัวอื่นๆไปด้วย ถ้ารับแค่ $_GET['url'] ค่าอื่นๆจะหายไป

ก็เลยต้อง build ค่าเพิ่มโดยตัดตัวที่ใช้หลักๆคือ url ออกไปก่อนด้วย unset() แล้วจึงสั่ง build ค่าขึ้นมาใหม่เพื่อส่งไปยังหน้าต่อไปได้ครบถ้วนนั่นเอง

-------

http_build_query (PHP 5, PHP 7)
Generate URL-encoded query string

https://www.php.net/manual/en/function.http-build-query.php








PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

PHP CI MANIA - การใช้งานคุณสมบัติใหม่ UPDATE Code ไปยัง Project โดยไม่ต้องคัดลอกทีละไฟล์

โดย SONGCHAI SAETERN

เพิ่มความสามารถใหม่ UPDATE ไฟล์ที่มีการ Generate ล่าสุดตามวันที่ที่กำหนด ไปยัง example_project หรือ โฟลเดอร์โปรเจ็กต์ที่ต้องการได้



สมาชิกอัพเดตได้ที่
http://fastcoding.phpcodemania.com/index.php/downloads


วิดีโอแนะนำการใช้งาน
PHP CI MANIA - การใช้งานคุณสมบัติใหม่ UPDATE Code ไปยัง Project โดยไม่ต้องคัดลอกทีละไฟล์







PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

การนำโค้ดที่ Generate จาก PHP CI MANIA ไปใช้งานในโปรเจ็กต์อื่นๆ ที่ไม่ใช่ Template ที่เตรียมมาด้วย

โดย SONGCHAI SAETERN
การนำโค้ดที่ Generate จาก PHP CI MANIA ไปใช้งานในโปรเจ็กต์อื่นๆ ที่ไม่ใช่ Template ที่เตรียมมาด้วยกับด้วยโปรแกรม จะต้องตั้งมีไฟล์และตั้งค่าดังต่อไปนี้



ส่วนที่ 1 ต้องมีโฟลเดอร์และไฟล์ใน assets ดังนี้


ส่วนที่ 2 ในโฟลเดอร์ของ application ตั้งค่าดังต่อไปนี้

เปิดไฟล์ application/config/autoload.php และเพิ่มส่วนของ libraries และ helper
เปิดไฟล์ application/config/config.php และเพิ่มโค้ดด้านล่างนี้ไว้ส่วนท้าย
/*
  |--------------------------------------------------------------------------
  | HMVC Modular
  |--------------------------------------------------------------------------
  |
  | Modules location
 */
$config['modules_locations'] = array(
    APPPATH . 'modules/' => '../modules/',
);


ส่วนที่ 3 ต้องมีโฟลเดอร์และไฟล์ใน application ดังนี้



กรณีที่ขาดไฟล์ที่จำเป็นต้องใช้จะพบ Error แจ้งเตือน สามารถคัดลอกไฟล์มาจากโฟลเดอร์ example_project ที่มาพร้อมตัวโปรแกรม PHP CI MANIA มาใช้ได้เลยครับ


สำคัญมาก

ส่วนสำคัญอีกอย่างก็คือ ใน homepage_view จะต้องมีการแทรกสคริปต์หลักสองส่วน
1. อยู่ใน <head>......</head>
2. อยู่ท้ายสุดของหน้าเว็บก่อน </body>



 
<!-- Require -->
<link href="{base_url}assets/bootstrap_extras/select2/select2.css" rel="stylesheet">
<link href="{base_url}assets/css/jquery-ui.min.css" rel="stylesheet">

{another_css}
<style>
div[data-notify="container"]{
z-index : 3000!important;
}

#exampleAccordion{
overflow-y: auto;
overflow-x: hidden;
}

.content-wrapper{
overflow-x: auto;
}

.card .bg-primary .card-title {
color: white;
}

div.alert span[data-notify="message"] p{
margin-bottom: 0px !important;
}

.upload-box .btn-file {
        background-color: #22b5c0;
}
.upload-box .hold {
    float: left;
    width: 100%;
    position: relative;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 4px;
}
.upload-box .hold span {
    font: 400 14px/36px 'Roboto',sans-serif;
    color: #666;
    text-decoration: none;
}

.upload-box .btn-file {
    position: relative;
    overflow: hidden;
    float: left;
    padding: 2px 10px;
    font: 900 14px/14px 'Roboto',sans-serif;
    color: #fff !important;
    margin: 0 10px 0 0;
    text-transform: uppercase;
    border-radius: 3px;
    cursor: pointer;
}
.upload-box .btn-file input[type=file] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 100px;
    text-align: right;
    opacity: 0;
    outline: none;
    background: #fd0707;
    cursor: inherit;
    display: block;
}
.div_file_preview {
background-color: #fefcfc;
border: 1px dashed #ccc;
}
.navbar-nav .nav-item .nav-link .badge{
margin-left: -0.3rem;
}
.select2-container .select2-choice {
height: 38px;
line-height: 36px;
}
.select2-container .select2-choice .select2-arrow b {
background-position: 0 5px;
}
/* ปรับสีเทมเพลต */
nav.navbar{
background-color : #337ba4 !important;
}
.sidebar{
background-color : #223344;
}
</style>

<script>
var baseURL = '{base_url}/';
var siteURL = '{site_url}/';
var csrf_token_name = '{csrf_token_name}';
var csrf_cookie_name = '{csrf_cookie_name}';
</script>
</head>




    
        <!-- Require -->
        <script src="{base_url}assets/js/jquery-ui.min.js"></script>
        <script src="{base_url}assets/bootstrap_extras/sweetalert/dist/sweetalert.min.js"></script>
<script src="{base_url}assets/bootstrap_extras/bootstrap-notify.min.js"></script>
<script src="{base_url}assets/bootstrap_extras/select2/select2.min.js"></script>
        <script src="{base_url}assets/js/jquery.cookie.min.js"></script>
        <script src="{base_url}assets/js/ci_utilities.js?ver=1541805506"></script>

{another_js}
</body>




คู่มือ PHP CI MANIA
https://phpcodemania.blogspot.com/p/php-ci-mania.html

แจก Bootstrap Template สวยๆ สำหรับใช้งานกับ PHP CI MANIA

https://github.com/sunzandesign/codeigniter_bootstrap_themes





PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

แจก Bootstrap Template สวยๆ สำหรับใช้งานกับ PHP CI MANIA (CodeIgniter)

โดย SONGCHAI SAETERN

แจก Bootstrap Template สวยๆ สำหรับใช้งานกับ PHP CI MANIA





ดาวน์โหลดได้ที่
https://github.com/sunzandesign/codeigniter_bootstrap_themes


วิธีติด Bootstrap Template (AdminLTE) เพิ่มเติม เพื่อใช้งานกับ PHP CI MANIA
https://www.youtube.com/watch?v=gzwKUPY-XG4

การเปลี่ยน Template ของ Project ด้วย Bootstrap Template
https://www.youtube.com/watch?v=kFa6aUA-HOM

การนำโค้ดที่ Generate จาก PHP CI MANIA ไปใช้งานในโปรเจ็กต์อื่นๆ ที่ไม่ใช่ Template ที่เตรียมมาด้วย (ใช้งานกับโปรเจ็กต์ CodeIgniter งานเก่าๆ)
https://phpcodemania.blogspot.com/2019/12/how-to-use-code-generate-php-ci-mania-another-project.html




PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม
http://fastcoding.phpcodemania.com

PHP CI MANIA การแก้ไขโค้ดหน้าแสดงรายละเอียด ให้ข้อมูลจากฟิลด์ Text แสดงข้อความหลายบรรทัด

โดย SONGCHAI SAETERN
การขึ้นบรรทัดใหม่หลายบรรทัดในส่วนของหน้าเว็บ Preview





คู่มือ PHP CI MANIA

https://phpcodemania.blogspot.com/p/php-ci-mania.html










PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
 http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com

PHP CI MANIA เพิ่มช่อง INPUT ค้นหาเพิ่มเติมจาก Dropdown List ที่ Generate ให้ (Option List)

โดย SONGCHAI SAETERN
การค้นหาในหน้าแสดงรายการ นอกจากจะใช้กล่องค้นหาที่เตรียมไว้ให้โดยเลือกฟิลด์ที่ต้องการจาก Drop-down list เรายังสามารถเพิ่มเติมช่องค้นหาได้เองโดยเขียนโค้ดเพิ่ม 3 ส่วนด้วยกัน ยกตัวอย่างเช่น

หน้าแสดงรายชื่อนักเรียน Student ในโมดูล demo จะประกอบด้วยไฟล์ดังนี้


1. แก้ไขที่ส่วนของ Views ที่ไฟล์ demo/views/student/list_view.php
    ไปที่ส่วนของกล่องค้นหา แทรกโค้ดต่อไปนี้ก่อนปุ่ม "ค้นหา"
<div class="form-check form-check-inline">
<input  type="radio" {check1}
name="sex" id="sex1"
value="1" class="form-check-input"
autocomplete="off"  />
<label class="form-check-label" for="sex1">ชาย</label>
</div>
<div class="form-check form-check-inline">
<input  type="radio" {check2}
name="sex" id="sex2"
value="2" class="form-check-input"
autocomplete="off"  />
<label class="form-check-label" for="sex2">หญิง</label>
</div>

2. แก้ไขที่ส่วนของ Model ที่ไฟล์ demo/models/Student_model.php
    ไปที่ฟังก์ชั่น read() และเพิ่มเติมโค้ดดังนี้

            *** แก้ไขเพิ่มเติม รับค่า sex มาจาก SESSION
            $sex = $this->session->userdata($this->session_name . '_sex');
$sex = $this->input->post('sex', TRUE);
if($sex != ''){
$sex = $sex + 0;
$where .= ($where != '' ? ' AND ' : '') . " $this->my_table.sex = $sex "; }


3. แก้ไขที่ส่วนของ Controller ที่ไฟล์ demo/controllers/Student.php
    ไปที่ฟังก์ชั่น search() และเพิ่มตัวแปรเพื่อแสดงค่าที่กำลังค้นหาปัจจุบัน

            *** แก้ไขเพิ่มเติม เก็บค่า sex ใน SESSION
            if (isset($_POST['submit'])) {
$search_field =  $this->input->post('search_field');
$value = $this->input->post('txtSearch');
$sex = $this->input->post('sex', TRUE);
$arr = array(
$this->Student->session_name . '_search_field' => $search_field, 
$this->Student->session_name . '_value' => $value,
$this->Student->session_name . '_sex' => $sex
);
$this->session->set_userdata($arr);
} else {
$search_field = $this->session->userdata($this->Student->session_name . '_search_field');
$value = $this->session->userdata($this->Student->session_name . '_value');
$sex = $this->session->userdata($this->Student->session_name . '_sex');
}

$sex = $this->input->post('sex', TRUE);
$check1 = '';
$check2 = '';
if($sex == 1){
$check1 = 'checked="checked"';
}else if($sex == 2){
$check2 = 'checked="checked"';
}
$this->data['check1'] = $check1;
$this->data['check2'] = $check2;



ดูคลิปตัวอย่างการแก้ไขแบบเต็มๆได้ที่ยูทูปแชนแนล PHP FAST CODING





*** แก้ไขปัญหา ไม่จำ SESSION ที่ค้นหาเมื่อเปลี่ยนหน้า ***



PHP CI MANIA - PHP Code Generator 

โปรแกรมช่วยสร้างโค้ด "ลดเวลาการเขียนโปรแกรม"
http://fastcoding.phpcodemania.com/index.php/#purchase-order
สนใจสั่งซื้อราคาสุดคุ้ม 1,500 บาท
http://fastcoding.phpcodemania.com