Codeigniter Project Tips

edited January 2021 in PHP

1.Set default timezone in application/config/config.php, so that this timezone will be applied to the whole project

date_default_timezone_set('Asia/Kolkata');


2.Avoid using static URL, instead use base_url function so that if change project path in one place it will reflect everywhere automatically

Do:

<?php base_url(); ?>images/logo-new-al.png

Don't:

https://gengroup.in/genesis-new/images/logo-new-al.png


3.Remove index.php from URL Path

Right:

https://apps.webgrid.in/bpocp/auth/login

Wrong:

https://apps.webgrid.in/bpocp/index.php/auth/login

How to:


4.Common CodeIgniter Model


5.Admin Panel URLs should not be accessible through static link

Write authentication code and admin panel code in two separate controllers and write a checking condition in constructor of admin panel code.

How To:

Write similar code in admin panel controller :

    <?php
    defined('BASEPATH') or exit('No direct script access allowed');
    class Home extends CI_Controller
    {
        public function __construct()
        {
            parent::__construct();
            //session checking code start
            if (!(isset($_SESSION["is_logged_in"]) && $_SESSION["is_logged_in"] == 1)) {
                redirect("auth/login");
            }
            //session checking code end
        }


Sign In or Register to comment.