Giter Site home page Giter Site logo

nguyenanhung / codeigniter-framework Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 4.0 1.17 MB

CodeIgniter Framework Version 3 - Vendor Packages build - Maintain by @nguyenanhung

Home Page: https://packagist.org/packages/nguyenanhung/codeigniter-framework

License: MIT License

PHP 99.82% HTML 0.18%
codeigniter codeigniter-hmvc codeigniter3 php codeigniter-starterkit codeigniter-library codeigniter-skeleton

codeigniter-framework's Introduction

CodeIgniter v3.2.0 - vendor packages build

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Bản đóng gói lại thư mục system framework của CodeIgniter, sử dụng tương thích với Composer và PHP 7, PHP 8

Kể từ phiên bản v3.2.0 - framework hoàn toàn tương thích với phiên bản PHP 8.2

Bản đóng gói này được liên tục cập nhật với các feature mới từ nhánh CodeIgniter3 nguyên bản. Vì vậy nó luôn được cập nhật các bản vá lỗi và bổ sung thêm nhiều tính năng mới

Mục lục


Các tính năng chính

Bổ sung thêm 1 số thư viện mở rộng, helpers liên quan

  • Base Controllers với nhiều protected method sẵn có
  • Support mô hình HMVC
  • Support RESTful Web Service
  • Support Queue Worker
  • Support CSDL MongoDB
  • Support Elasticsearch: Use third party packages "elasticsearch/elasticsearch": "^8.0 || ^7.0 || ^6.0 || ^5.0"
  • Support class Base Model với 1 số hàm cơ bản đủ dùng với SQL
  • Support class ORM Model, cung cấp 1 phương thức đơn giản và dễ dàng hơn để query
  • Hỗ trợ Output Response trên giao diện CLI thông qua hàm ResponseOutput::writeLn($message)
  • Bổ sung class StatusCodes khai báo sẵn các HTTP code tuân chuẩn (from Symfony framework), VD: StatusCodes::HTTP_OK. Chi tiết tham khảo thêm tại class StatusCodes
  • Bổ sung rất nhiều helper tiện dụng với việc tích hợp sẵn gói nguyenanhung/codeigniter-basic-helper thông qua Composer

Hướng dẫn cài đặt gói vào trong dự án

  1. Cài đặt gói vào trong dự án với lệnh sau
composer require nguyenanhung/codeigniter-framework
  1. Cập nhật file index.php

Tìm dòng

/*
 *---------------------------------------------------------------
 * SYSTEM DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" directory.
 * Set the path if it is not in the same directory as this file.
 */
	$system_path = 'system';

Sửa thành như sau

/*
 *---------------------------------------------------------------
 * SYSTEM DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" directory.
 * Set the path if it is not in the same directory as this file.
 */
	$system_path = '/your_vendor_path/nguyenanhung/codeigniter-framework/system';
  1. Xoá thư mục system trong thư mục gốc dự án đi cho gọn

Hướng dẫn sử dụng

Hướng dẫn viết Controller kế thừa Base Controller

Trong thư viện đã xây dựng sẵn 1 Base Controller, kế thừa như sau

  1. Xây dựng 1 Controller mới theo tài liệu CodeIgniter 3
  2. Kế thừa class từ HungNG_CI_Base_Controllers thay vì CI_Controller, ví dụ như sau
<?php
/**
 * Class Hungna_test
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class Hungna_test extends HungNG_CI_Base_Controllers
{
	public function __construct()
    {
        parent::__construct();
    }
  	
  	public function index()
    {
		echo "This is ".get_class($this); // show: This is Hungna_test
		exit();
    }
}

Hướng dẫn viết Controller chạy Queue Worker

Trong thư viện đã xây dựng sẵn 1 Base Queue Worker (được xây dựng bởi yidas), kế thừa như sau

  1. Xây dựng 1 Controller mới theo tài liệu CodeIgniter 3
  2. Kế thừa class từ HungNG_CI_Base_Queue_Worker thay vì CI_Controller, ví dụ như sau
<?php
/**
 * Class My_worker
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class My_worker extends HungNG_CI_Base_Queue_Worker
{
    // Initializer
    protected function init() {}
    
    // Worker
    protected function handleWork() {}
    
    // Listener
    protected function handleListen() {}
}

Tìm hiểu thêm chi tiết tài liệu tại đây: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-queue-worker

Hướng dẫn viết Controller chạy RESTful API Service

Trong thư viện đã xây dựng sẵn 1 Base RESTful (được xây dựng bởi yidas), kế thừa như sau

  1. Xây dựng 1 Controller mới theo tài liệu CodeIgniter 3
  2. Kế thừa class từ HungNG_CI_Base_REST thay vì CI_Controller, ví dụ như sau
<?php
/**
 * Class My_rest_api
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class My_rest_api extends HungNG_CI_Base_REST
{
    public function index()
    {
        return $this->response->json(['bar'=>'foo']);
    }
    
	public function store($requestData=null) {
	
	    $this->db->insert('mytable', $requestData);
	    $id = $this->db->insert_id();
	    
	    return $this->response->json(['id'=>$id], 201);
	}
}

Tìm hiểu thêm chi tiết tài liệu tại đây: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-rest

Hướng dẫn viết Model kế thừa Base Model

  1. Xây dựng 1 model theo tài liệu CodeIgniter 3
  2. Kế thừa class từ HungNG_Custom_Based_model thay vì CI_Model, ví dụ như sau
<?php
defined('BASEPATH') or exit('No direct script access allowed');

/**
 * Class Credentials_model
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 * @property \CI_DB_query_builder $db
 */
class Credentials_model extends HungNG_Custom_Based_model
{
    const IS_ACTIVE = 1;
    const ROLE_PUSH = 1;
    const ROLE_PULL = 2;
    const ROLE_FULL = 3;

    protected $fieldUsername;
    protected $fieldStatus;
    protected $fieldRole;

    /**
     * Credentials_model constructor.
     *
     * @author   : 713uk13m <[email protected]>
     * @copyright: 713uk13m <[email protected]>
     */
    public function __construct()
    {
        parent::__construct();
        $this->db            = $this->load->database('default', true, true);
        $this->tableName     = 'credentials';
        $this->primary_key   = 'id';
        $this->fieldUsername = 'username';
        $this->fieldStatus   = 'status';
        $this->fieldRole     = 'role';
    }
}

Hướng dẫn viết Model kế thừa Base ORM Model

  1. Package này bổ sung thêm 1 phương án viết model hiện đại theo phong cách ORM với Elegant patterns giống như Laravel Eloquent ORM & Yii2 Active Record (được xây dựng bởi yidas)
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-orm-model

Hướng dẫn tích hợp SEO cơ bản

  1. Package này bổ sung thêm 1 thư viện và helper SEO đơn giản
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/blob/main/codeigniter3-basic-seo/README.md

Hướng dẫn sử dụng CSDL MongoDB trong dự án

  1. Mặc định, CodeIgniter v3 không hỗ trợ MongoDB. Tuy nhiên không vì thế mà hạn chế, CodeIgniter là framework mở, vì vậy tôi đã bổ sung thêm 1 thư viện hỗ trợ việc gọi, tương tác, xử lý với CSDL MongoDB mà cách sử dụng cũng tương đối giống với Query Builder của CodeIgniter
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-mongodb

Hướng dẫn sử dụng Elasticsearch trong dự án

  1. Mặc định, CodeIgniter v3 không hỗ trợ Elasticsearch. Tuy nhiên không vì thế mà hạn chế, CodeIgniter là framework mở, vì vậy tôi đã bổ sung thêm 1 thư viện hỗ trợ việc gọi, tác với Elasticsearch
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-elasticsearch

Hướng dẫn tích hợp mô hình HMVC vào dự án

  1. Create folder: modules trong thư mục application. Tham khảo cấu trúc thư mục modules-samples tại https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/modules-sample
.
└── modules
    └── startup
        ├── config
        │   ├── index.html
        │   └── routes.php
        ├── controllers
        │   ├── Startup.php
        │   └── index.html
        ├── index.html
        ├── models
        │   ├── Startup_model.php
        │   └── index.html
        └── views
            └── index.html

6 directories, 8 files
  1. Create file hmvc.php với nội dung như sau
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| HMVC settings
| -------------------------------------------------------------------------
| See: https://github.com/nguyenanhung/CodeIgniter-HMVC
|
*/
$config['modules_locations'] = array(
    APPPATH . 'modules/' => '../modules/'
);
  1. Nạp file hmvc.php vào file config.php
require_once __DIR__ . '/hmvc.php';
  1. Create file MY_Loader.php trong thư mục application/core/ có nội dung như sau
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
 * Class MY_Loader
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class MY_Loader extends HungNG_Loader
{

}
  1. Create file MY_Router.php trong thư mục application/core/ có nội dung như sau
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
 * Class MY_Router
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class MY_Router extends HungNG_Router
{

}
  1. Triển khai viết code trong thư mục modules mới, tương tự như sau
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
 * Class TestModule
 *
 * @author    713uk13m <[email protected]>
 * @copyright 713uk13m <[email protected]>
 */
class TestModule extends HungNG_CI_Base_Module
{
	public function __construct()
    {
        parent::__construct();
    }
  	
	public function index()
    {
		echo "This is ".get_class($this); // show: This is TestModule
		exit();
    }
}

Hướng dẫn sử dụng kiểm tra các filename trong dự án của bạn đã đúng chuẩn của CodeIgniter hay chưa

  1. This controller checks CodeIgniter 3.0 class filename.
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter3-filename-checker

Hướng dẫn sử dụng ghi log tất cả các queries trong CodeIgniter và ghi lại Execution Time của từng Queries

  1. Mặc định, CodeIgniter v3 không hỗ trợ ghi log Execution Time của các Queries. Tuy nhiên, có thể sử dụng Hooks để thực hiện điều này
  2. Đọc tài liệu chi tiết về cách tích hợp và triển khai tại đây với những ví dụ trực quan và cụ thể: https://github.com/nguyenanhung/codeigniter-framework-sample/tree/main/codeigniter-log-all-queries

CodeIgniter Basic Helper

  • Trong nhiều năm làm lập trình với CodeIgniter, tôi đã sưu tập, xây dựng và viết được kha khá helper, tôi đã đóng gói chúng lại thành gói nguyenanhung/codeigniter-basic-helper và tích hợp vào bên trong gói này.
  • Gói helper này vẫn đang được tôi vận hành và phát triển hàng ngày, số project tích hợp các hàm trong gói này đã lên con số hàng nghìn
  • Thông tin chi tiết hơn về bộ helper này https://github.com/nguyenanhung/codeigniter-basic-helper

Liên hệ

Name Email Skype Facebook Website
Hung Nguyen [email protected] nguyenanhung5891 @nguyenanhung https://nguyenanhung.com

codeigniter-framework's People

Contributors

hungnguyenhp avatar nguyenanhung avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

codeigniter-framework's Issues

Lỗi khi dùng với php 8.2

A PHP Error was encountered
Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Pagination.php

Line Number: 517

Lỗi này khắc phục sao vậy anh?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.