Set up pure CodeIgniter

Environment

  • Codeigniter 3.0.0
  • PHP5.4
  • MySQL5.6


Change file structure

project/
     |- public_html/
     |        |- index.php
     |        |- images/
     |        |- css/
     |        |- less/
     |        |- javascripts/
     |
     |- application/
     |        |- cache/
     |        |- config/
     |        |- controllers/
     |        |- core/
     |        |- errors/
     |        |- helpers/
     |        |- hooks/
     |        |- language/
     |        |- libraries/
     |        |- logs/
     |        |- models/
     |        |- third_party/
     |        |- views/
     |
     |- system/
              |- core/
              |- database/
              |- fonts/
              |- helpers/
              |- language/
              |- libraries/


Change permission

% chmod 777 project/application/logs
% chmod 777 project/public_html


Set up index.php

public_html/index.php

// $system_path = 'system';
$system_path = '../system';

// $application_folder = 'application';
$application_folder = '../application';


Set default controller

$route['default_controller'] = 'top';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;


Set up database.php

/application/config/database.php

$db['default'] = array(
    'dsn' => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'database' => 'test',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);


Set up autoload.php

/application/config/autoload.php

//$autoload['libraries'] = array();
$autoload['libraries'] = array('database', 'session');

//$autoload['helper'] = array();
$autoload['helper'] = array('url');


You can connect databases automatically as below.

$this->load->model('Model_name', '', TRUE);


Set up config.php

In case of need the session library, you need to set the encryption_key.

/application/config/config.php

$config['encryption_key'] = 'fehiCFEffwfjoejgheog09845u30thFSAF';


Create table

CREATE TABLE `user` (
  `id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(64) NOT NULL,
  `email` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `token` varchar(64) NOT NULL,
  `created_at` datetime NOT NULL,
  `created_by` varchar(45) NOT NULL,
  `updated_at` datetime NOT NULL,
  `updated_by` varchar(45) NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `token_UNIQUE` (`token`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
insert into user (username, email, password) values ('testuser', 'test@test.com', MD5('password'), '', NOW(), 'system', NOW(), 'system');


Attention

You should not use xss_clean on password.