Thumbnail
Category: Lập trình

Kinh nghiệm Codeigniter - Perfex CRM

Date: April 13, 2022
8 views

1. Config một project mới

Vào application/config/config.php => chỉnh APP_BASE_URL, chỉnh thông tin database

Tạo file .htaccess ở ngoài thư mục gốc cùng cấp file index.php


<IfModule mod_rewrite.c>
RewriteEngine On
​
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

2. Router

url/[ControllerName]/[method]/[param1]/[param2]…

có thể config route lại trong file application/config/route.php



$route['clients/login']           = 'authentication/login'; // bên phải là tên Controller/tên method

3. Middleware

Chặn ngay constructor của class.

Đá login do ValidatesContact thực hiện



<?php
​
defined('BASEPATH') or exit('No direct script access allowed');
​
use app\services\ValidatesContact;
​
class Clients extends ClientsController
{
    /**
     * @since  2.3.3
     */
    use ValidatesContact;
​
    public function __construct()
    {
        parent::__construct();
​
        hooks()->do_action('after_clients_area_init', $this);
    }

Copyright © 2025 All Right Reserved