项目作者: ngthucdotcom

项目描述 :
CodeIgniter core custom by ngthuc
高级语言: PHP
项目地址: git://github.com/ngthucdotcom/ci-composer.git
创建时间: 2019-11-28T01:31:38Z
项目社区:https://github.com/ngthucdotcom/ci-composer

开源协议:MIT License

下载


Server Requirements

  • OS: Linux 18.04 (recommended)
  • PHP: PHP 5.6 or newer

Installation

Create project

  1. Run composer create project (for init new project) or update (for reload dependencies on new environment) via command line at root folder
  • Create project
    1. composer create-project ngthuc/ci-composer
  • Reload dependencies
    1. composer update
  1. Create .env file same [.]env to set-up database

    Require project into another project

  2. Run composer require project (for init new project) or update (for reload dependencies on new environment) via command line at root folder
  • Require project
    1. composer require ngthuc/ci-composer
  • Reload dependencies
    1. composer update
  1. Move all files from /vendor/ngthuc/ci-composer/app/ to the root folder structure:
    1. root # → Root Directory
    2. └── vendor/
    3. └── ngthuc/
    4. └── ci-composer/
    5. └── app/
    6. ├── apllication/
    7. ├── public/
    8. ├── .bowerrc
    9. ├── .editorconfig
    10. ├── .gitignore
    11. ├── .htaccess
    12. ├── [.]env
    13. ├── bower.json
    14. ├── index.php
    15. └── license.txt
  2. Create .env file same [.]env to set-up database

Usage

  • Use Apache - MySQL/MariaDB - PHP (AMP) stack as a software (e.g., XAMPP/AMPPS/WAMP)
  • Install AMP stack packages on Linux or Windows, and move project to root directory of Apache (e.g., www/) and use built-in web server (with PHP 5.4.0 or newer) via command:
    1. php -S <address>:<port> -t <YOUR_PROJECT_FOLDER></YOUR_PROJECT_FOLDER>
    2. # Example use this command on root directory
    3. php -S localhost:8000

Usage RestAPI

CodeIgniter Rest Server is available on package.

Step 1: Add this to your controller (should be before any of your code)

  1. use chriskacerguis\RestServer\RestController;

Step 2: Extend your controller

  1. class Example extends RestController

Basic GET example

Here is a basic example. This controller, which should be saved as Api.php, can be called in two ways:

  • http://domain/api/users/ will return the list of all users
  • http://domain/api/users/id/1 will only return information about the user with id = 1
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. use chriskacerguis\RestServer\RestController;
  4. class Api extends RestController {
  5. function __construct()
  6. {
  7. // Construct the parent class
  8. parent::__construct();
  9. }
  10. public function users_get()
  11. {
  12. // Users from a data store e.g. database
  13. $users = [
  14. ['id' => 0, 'name' => 'John', 'email' => 'john@example.com'],
  15. ['id' => 1, 'name' => 'Jim', 'email' => 'jim@example.com'],
  16. ];
  17. $id = $this->get( 'id' );
  18. if ( $id === null )
  19. {
  20. // Check if the users data store contains users
  21. if ( $users )
  22. {
  23. // Set the response and exit
  24. $this->response( $users, 200 );
  25. }
  26. else
  27. {
  28. // Set the response and exit
  29. $this->response( [
  30. 'status' => false,
  31. 'message' => 'No users were found'
  32. ], 404 );
  33. }
  34. }
  35. else
  36. {
  37. if ( array_key_exists( $id, $users ) )
  38. {
  39. $this->response( $users[$id], 200 );
  40. }
  41. else
  42. {
  43. $this->response( [
  44. 'status' => false,
  45. 'message' => 'No such user found'
  46. ], 404 );
  47. }
  48. }
  49. }
  50. }

Author

Credit

This project using projects or dependencies:

License

CodeIgniter Core Custom is licensed under MIT License.