takuya-motoshima / codeigniter-extension
Extend CodeIgniter for ease of use
Installs: 4 542
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 4
Language:JavaScript
Requires
- php: ^7.0
- ext-openssl: ^7.3
- 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-master
- 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.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.9
- 3.4.8
- 3.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and_yarn/sample/client/webpack-5.76.0
This package is auto-updated.
Last update: 2024-04-15 09:49:19 UTC
README
You can use extended core classes (controllers, models, views) and utility classes in this package.
Click here to see the change log.
There is a sample application in sample.
Please use it as a reference for your development.
Requirements
- PHP 7.3.0 or later
- Composer
- php-gd
- php-mbstring
- php-xml
- php-imagick
The method to extract the first frame from a GIF ("extractFirstFrameOfGif") in the "\X\Util\ImageHelper" class requires ImageMagick.
To use this method, install ImageMagick and php-imagick.
The following command is an example installation on my Amazon Linux2 OS.sudo yum -y install ImageMagick php-imagick
Getting Started
- Create project.
composer create-project takuya-motoshima/codeIgniter-extension myapp
- Grant write permission to logs, cache, session to WEB server.
sudo chmod -R 755 public/upload application/{logs,cache,session} sudo chown -R nginx:nginx public/upload application/{logs,cache,session}
- Set up a web server (nginx).
If you are using Nginx, copy nginx.sample.conf to "/etc/nginx/conf.d/sample.conf".
Restart Nginx.sudo systemctl restart nginx
- Build a DB for create-db.sql (MySQL or MariaDB).
- The skeleton uses webpack for front module bundling.
The front module is located in ". /client".
How to build the front module:cd client npm run build
- Open "http://{public IP of the server}:3000/" in a browser and the following screen will appear.
NOTE: You can log in with the username "robin@example.com" and password "password".
Usage
See https://codeigniter.com/userguide3/ for basic usage.
-
About config (application/config/config.php).
Name Before After base_url if (!empty($_SERVER['HTTP_HOST'])) $config['base_url'] = '//' . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); 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 -
Control of accessible URLs.
-
Define a controller to be executed when the root URL is accessed.
In the example below, the login page is set to open when the root URL is accessed.application/config/routes.php:
$route['default_controller'] = 'users/login';
-
Define login session name.
application/config/constants.php:const SESSION_NAME = 'session';
-
Create control over which URLs can be accessed depending on the user's login status.
At the same time, add env loading and error handling in "pre_system".application/config/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); $isLogin = !empty($_SESSION[SESSION_NAME]); $currentPath = lcfirst($CI->router->directory ?? '') . lcfirst($CI->router->class) . '/' . $CI->router->method; $defaultPath = '/users/index'; $allowRoles = !empty($meta->allow_role) ? array_map('trim', explode(',', $meta->allow_role)) : null; if (!$meta->allow_http) throw new \RuntimeException('HTTP access is not allowed'); else if ($isLogin && !$meta->allow_login) redirect($defaultPath); else if (!$isLogin && !$meta->allow_logoff) redirect('/users/login'); else if ($isLogin && !empty($allowRoles)) { $role = $_SESSION[SESSION_NAME]['role'] ?? ''; if (!in_array($role, $allowRoles) && $defaultPath !== $currentPath) redirect($defaultPath); } }; $hook['pre_system'] = function () { $dotenv = Dotenv\Dotenv::createImmutable(ENV_DIR); $dotenv->load(); set_exception_handler(function ($e) { Logger::error($e); show_error($e->getMessage(), 500); }); };
-
After this, you will need to create controllers, models, and views, see the sample for details.
-
-
About Twig Template Engine.
This extension package uses the Twig template.
See here for how to use Twig.In addition, the session of the logged-in user is automatically set in the template variable.
This is useful, for example, when displaying the login username on the screen.PHP:
$_SESSION['user'] = ['name' => 'John Smith'];
HTML:
{% if session.user is not empty %} Hello {{session.user.name}}! {% endif %} Who is it? {% else %}
-
To extend form validation.
You can create a new validation rule by creating "application/libraries/AppForm_validation.php" as follows and adding a validation method.use X\Library\FormValidation; class AppForm_validation extends FormValidation { public function is_numeric(string $input): bool { if (!is_numeric($input)) { $this->set_message('is_numeric', 'Please enter a numerical value'); return false; } return true; } }
The following extended validations are available in the CodeIgniter extension from the start.
Rule Parameter Description Example datetime Yes If the value is other than a date, FALSE is returned.. datetime[Y-m-d H:i:s] hostname No If the value is other than the host name, FALSE is returned. ipaddress No If the value is other than an IP address, FALSE is returned. hostname_or_ipaddress No If the value is other than a host name or IP address, FALSE is returned. unix_username No If the value is other than a Unix username, FALSE is returned. port No If the value is other than a port number, FALSE is returned. email No If the value is other than the email suggested in HTML5, FALSE will be returned.
https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
Unit testing
The unit test consists of the following files.
- tests/*.php: Test Case.
- phpunit.xml: Test setting fill.
- phpunit-printer.yml: Test result output format.
Run a test.
composer test
Author
Takuya Motoshima