takuya-motoshima / codeigniter-extension
Extend CodeIgniter for ease of use
Package info
github.com/shumatsumonobu/codeigniter-extension
Language:JavaScript
pkg:composer/takuya-motoshima/codeigniter-extension
Requires
- php: ^8.0
- ext-openssl: *
- aws/aws-sdk-php: ^3.64
- codeigniter/framework: 3.1.*
- doctrine/common: ^2.10
- hybridauth/hybridauth: 2.*
- intervention/image: ^2.5
- mathieuviossat/arraytotexttable: ^1.0
- twig/twig: 2.*
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32.0
- phpunit/phpunit: ^8.4
- dev-main
- v5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.20
- 4.1.9
- 4.1.8
- 4.1.7
- 4.1.6
- 4.1.5
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.25
- 4.0.24
- 4.0.23
- 4.0.22
- 4.0.21
- 4.0.20
- 4.0.19
- 4.0.18
- 4.0.17
- 4.0.16
- 4.0.15
- 4.0.14
- 4.0.13
- 4.0.12
- 4.0.11
- 4.0.10
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.9.9
- 3.9.8
- 3.9.7
- 3.9.6
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.9
- 3.8.8
- 3.8.7
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.9
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.5
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.9
- 3.6.8
- 3.6.7
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.9
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5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.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/demo/client/svgo-2.8.2
- dev-dependabot/npm_and_yarn/demo/client/axios-1.13.5
- dev-dependabot/npm_and_yarn/skeleton/client/axios-1.13.5
- dev-dependabot/npm_and_yarn/skeleton/client/webpack-5.105.0
- dev-feature/google-authenticator-mfa
- dev-dependabot/npm_and_yarn/demo/client/lodash-4.17.23
- dev-dependabot/npm_and_yarn/skeleton/client/lodash-4.17.23
- dev-dependabot/npm_and_yarn/demo/client/serialize-javascript-6.0.2
- dev-dependabot/npm_and_yarn/skeleton/client/braces-3.0.3
This package is auto-updated.
Last update: 2026-03-10 09:15:44 UTC
README
CodeIgniter Extension
Supercharge your CodeIgniter 3 workflow.
Extended controllers, models, utilities, and AWS integrations — all in one package.
日本語 | Changelog | 変更履歴 | API Docs
Why CodeIgniter Extension?
CodeIgniter 3 is fast and lightweight — but it lacks modern conveniences. This package fills the gaps without compromising simplicity.
| What you get | |
|---|---|
| Controllers | JSON / HTML / Twig responses, CORS, annotation-based access control |
| Models | Fluent query builder, INSERT ... ON DUPLICATE KEY UPDATE, helper methods |
| Utilities | Image/video processing, encryption, CSV, REST client, validation, logging |
| AWS | Rekognition (face detection & comparison), SES (email delivery) |
| Scaffold | One command to create a fully working app with auth, dashboard & frontend |
Quick Start
composer create-project takuya-motoshima/codeigniter-extension myapp
cd myapp
Set up permissions and web server:
sudo chmod -R 755 public/upload application/{logs,cache,session}
sudo chown -R nginx:nginx public/upload application/{logs,cache,session}
sudo cp nginx.sample.conf /etc/nginx/conf.d/myapp.conf
sudo systemctl restart nginx
Import the database and build assets:
mysql -u root -p your_database < skeleton/init.sql cd client && npm install && npm run build
Open http://{your-server-ip}:3000/ — default credentials: robin@example.com / password
Usage
Controller
use \X\Annotation\Access; class Users extends AppController { /** @Access(allow_login=true, allow_logoff=false, allow_role="admin") */ public function index() { $users = $this->UserModel->get()->result_array(); parent::set('users', $users)->view('users/index'); } /** @Access(allow_http=true) */ public function api() { parent::set(['message' => 'Success'])->json(); } }
Model
class UserModel extends AppModel { const TABLE = 'user'; public function getActiveUsers() { return $this ->where('active', 1) ->order_by('name', 'ASC') ->get() ->result_array(); } }
Utilities
use \X\Util\{ImageHelper, FileHelper, Cipher, RestClient}; // Image ImageHelper::resize('/path/to/image.jpg', '/path/to/output.jpg', 800, 600); // Files FileHelper::makeDirectory('/path/to/dir', 0755); // Encryption $encrypted = Cipher::encrypt('secret data', 'encryption-key'); // REST $client = new RestClient(['base_url' => 'https://api.example.com']); $response = $client->get('/users');
Twig Templates
Session variables are automatically available:
{% if session.user is defined %}
<p>Welcome, {{ session.user.name }}!</p>
{% if session.user.role == 'admin' %}
<a href="/admin">Admin Panel</a>
{% endif %}
{% endif %}
API at a Glance
Controller Methods
| Method | Description |
|---|---|
json() |
Send JSON response |
view($template) |
Render Twig template |
html($html) |
Send HTML response |
text($text) |
Send plain text response |
image($path) |
Send image response |
download($filename, $content) |
Force file download |
set($key, $value) |
Set response data |
setCorsHeader($origin) |
Set CORS headers |
Model Methods
| Method | Description |
|---|---|
get_all() |
Get all records |
get_by_id($id) |
Get record by ID |
count_by_id($id) |
Count records by ID |
exists_by_id($id) |
Check if record exists |
insert_on_duplicate_update() |
Upsert single record |
insert_on_duplicate_update_batch() |
Batch upsert |
Utility Classes
| Class | Key Methods |
|---|---|
ImageHelper |
resize(), crop(), writeDataURLToFile(), pdf2Image() |
FileHelper |
makeDirectory(), delete(), copyFile(), move() |
Cipher |
encrypt(), decrypt(), encode_sha256() |
RestClient |
get(), post(), put(), delete() |
Logger |
debug(), info(), error(), display() |
Validation |
hostname(), ipaddress(), email(), is_path() |
IpUtils |
isIPv4(), isIPv6(), inRange() |
Template |
load($template, $params) |
Configuration
Recommended config.php settings
| Setting | Default | Recommended |
|---|---|---|
base_url |
empty | Dynamic: '//' . $_SERVER['HTTP_HOST'] . ... |
enable_hooks |
FALSE |
TRUE |
permitted_uri_chars |
a-z 0-9~%.:_\- |
a-z 0-9~%.:_\-, |
sess_save_path |
NULL |
APPPATH . 'session' |
cookie_httponly |
FALSE |
TRUE |
composer_autoload |
FALSE |
realpath(APPPATH . '../vendor/autoload.php') |
index_page |
index.php |
empty |
Access Control (hooks.php)
use \X\Annotation\AnnotationReader; use \X\Util\Logger; $hook['post_controller_constructor'] = function() { if (is_cli()) return; $CI =& get_instance(); $meta = AnnotationReader::getAccessibility($CI->router->class, $CI->router->method); $loggedin = !empty($_SESSION[SESSION_NAME]); if (!$meta->allow_http) throw new \RuntimeException('HTTP access is not allowed'); else if ($loggedin && !$meta->allow_login) redirect('/users/index'); else if (!$loggedin && !$meta->allow_logoff) redirect('/users/login'); };
Database Session Driver
PHP 7.0+ compatible session handler with custom column support:
$config['sess_driver'] = 'database'; $config['sess_save_path'] = 'session'; $config['sess_table_additional_columns'] = ['email'];
Implements updateTimestamp() to prevent Failed to write session data warnings.
Requirements
- PHP 8.0+
- Composer
- Extensions: php-gd, php-mbstring, php-xml, php-imagick (optional)
ImageMagick Installation
Required for extractFirstFrameOfGif() in \X\Util\ImageHelper.
Amazon Linux 2:
sudo yum -y install ImageMagick php-imagick
Amazon Linux 2023:
sudo dnf -y install ImageMagick ImageMagick-devel php-pear.noarch sudo pecl install imagick echo "extension=imagick.so" | sudo tee -a /etc/php.ini sudo systemctl restart nginx php-fpm
Architecture
src/X/
├── Annotation/ Access control annotations
├── Composer/ Post-install scaffolding
├── Constant/ Environment & HTTP status constants
├── Controller/ Base controller with response helpers
├── Core/ Extended Loader, Router, URI
├── Database/ Query builder, drivers, result set
├── Exception/ Custom exceptions
├── Hook/ Authentication hook
├── Library/ Form validation, input, session driver
├── Model/ Base model with query helpers
├── Rekognition/ AWS face detection & comparison
└── Util/ 21 utility classes
Testing
composer test
Documentation
Troubleshooting
| Problem | Solution |
|---|---|
| "Failed to write session data" warning | Use $config['sess_driver'] = 'database' — the included SessionDatabaseDriver handles PHP 7.0+ compatibility |
| Imagick extension not found | Install ImageMagick + php-imagick (see Requirements) |
@Access annotations ignored |
Enable hooks: $config['enable_hooks'] = TRUE and configure hooks.php |
| Twig templates not updating | Clear cache: rm -rf application/cache/templates/* |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
shumatsumonobu — GitHub / Twitter / Facebook

