Questions tagged [codeigniter]

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Created by EllisLab, fostered by BCIT it is now a project of the CodeIgniter Foundation. The framework implements a modified version of the Model-View-Controller design pattern. Use this tag for questions about CodeIgniter classes, methods, functions, syntax, and use. There are two major versions: 3.x and 4.x, addressing different system requirements

CodeIgniter is an web application framework created by EllisLab Inc and it is now a project of British Columbia Institute of Technology. The framework implements a modified version of the Model-View-Controller design pattern. It is praised for its performance and the quality of its documentation. It's currently licensed under the MIT License, although the previous version was released under the Open Software License ("OSL") v. 3.0.

CodeIgniter is an open source rapid development web application framework, for use in building dynamic websites with PHP. "Its goal is to enable [developers] to develop projects much faster than writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries." The first public version of CodeIgniter was released on February 28, 2006, and the latest stable version 3.1.10 was released January 16, 2019.

CodeIgniter is loosely based on the popular Model-View-Controller development pattern. While view and controller classes are a necessary part of development under CodeIgniter, models are optional.

With more than 18k star on Codeigniter's repository, it's also among the most starred PHP Framework on Github.com

These are generally regarded as pros of the framework:

  • Nearly zero configuration & No restrictive coding rules
  • Small footprint
  • Performance
  • Easy to learn
  • Great documentation
  • No restrictive coding rules

These are generally regarded as cons of the framework:

  • No built-in ORM
  • No built-in templating
  • Doesn't utilize namespaces
  • Doesn't utilize PHP's auto-loading feature
  • Application code is tightly-coupled with the framework

CodeIgniter Versions

Current Stable Version: 3.1.10 (Release Date: January 16, 2019)


Top Tips For Codeigniter

One of the most common asked questions in Codeigniter on Stack Overflow is when I view my page I get error 404 "Page Not Found". There are a couple of solutions you should look at before asking the question.

  1. Solution 1: Check the first letter of class name and filename of controller and models is the Uppercase example: Welcome.php

  2. Solution 2: If base_url() returns unexpected results, it's because you have not set a $config['base_url'] value.

  3. Solution 3: If you have not configured your CodeIgniter application/config/config.php file to remove $config['index_page'] = ''; then you will need to include the index.php in your URL

  4. Solution 4: After all settings you need to load the form url etc.. in autoload.php $autoload['helper'] = array('url', 'file','form','security');

http://www.example.com/index.php/site

Note you will need a .htaccess file when you are removing index.php .htaccess for Codeigniter 2 & 3


Frequently asked questions


Online resources

68242 questions
100
votes
5 answers

How to do error logging in CodeIgniter (PHP)

I want error logging in PHP CodeIgniter. How do I enable error logging? I have some questions: What are all the steps to log an error? How is an error log file created? How to push the error message into log file (whenever an error occurs)? How…
udaya
  • 8,618
  • 15
  • 46
  • 66
89
votes
9 answers

Going from a framework to no-framework

I've been developing in PHP for about 8 years as a hobby. In 2009, I picked up codeigniter and since then I've not managed to get a single project developed. I find it slows me down trying to work out how to modify it to work the way I want, when if…
Alex C
  • 1,371
  • 2
  • 12
  • 16
87
votes
6 answers

explain $CI =& get_instance();

Looking through codeigniter's source code, in its helper functions I keep seeing code $CI =& get_instance(); can anyone please explain to me how this code works? I get that it is returning a reference to the $CI super object, but where does…
Hailwood
  • 79,753
  • 103
  • 257
  • 412
86
votes
5 answers

Codeigniter - no input file specified

I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.
koool
  • 13,917
  • 11
  • 43
  • 60
84
votes
6 answers

Handling PUT/DELETE arguments in PHP

I am working on my REST client library for CodeIgniter and I am struggling to work out how to send PUT and DELETE arguments in PHP. In a few places I have seen people using the options: $this->option(CURLOPT_PUT,…
Phil Sturgeon
  • 29,768
  • 12
  • 74
  • 117
81
votes
11 answers

DataTables: Cannot read property 'length' of undefined

I understand this a popular issue, and I have read all the similar questions here on Stack Overflow and other sites (including the datatables website). To clarify, I am using PHP Codeigniter Materliazecss I have also made sure that I received the…
Abdelrahman Shoman
  • 2,420
  • 7
  • 32
  • 52
81
votes
11 answers

the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?

I'm researching hours and hours, but I could not find any clear, efficient way to make it :/ I have a codeigniter base website in English and I have to add a Polish language now. What is the best way to make my site in 2 language depending visitor…
designer-trying-coding
  • 5,636
  • 16
  • 66
  • 98
80
votes
9 answers

Sending email with gmail smtp with codeigniter email library

load->library('email'); } function index() { $config['protocol'] = 'smtp'; $config['smtp_host'] =…
Shiv
  • 845
  • 1
  • 7
  • 8
79
votes
11 answers

Inserting NOW() into Database with CodeIgniter's Active Record

I want to insert current time in database using mySQL function NOW() in Codeigniter's active record. The following query won't work: $data = array( 'name' => $name , 'email' => $email, 'time' => NOW() ); …
Roman
  • 3,704
  • 20
  • 48
  • 70
78
votes
11 answers

CodeIgniter - return only one row?

At the moment if I am doing a query on the database that should only return one row, using: ...query stuff... $query = $this->db->get(); $ret = $query->result(); return $ret[0]->campaign_id; Is there a CodeIgniter function to return the first…
Hailwood
  • 79,753
  • 103
  • 257
  • 412
75
votes
10 answers

How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?

I'm using CodeIgniter's Active Record class to query the MySQL database. I need to select the rows in a table where a field is not set to NULL: $this->db->where('archived !=', 'NULL'); $q = $this->db->get('projects'); That only returns this…
rebellion
  • 6,376
  • 11
  • 44
  • 76
73
votes
12 answers

CodeIgniter - how to catch DB errors?

Is there a way to make CI throw an exception when it encounters a DB error instead of displaying a message like: A Database Error Occurred Error Number: 1054 Unknown column 'foo' in 'where clause' SELECT * FROM (FooBar) WHERE foo =…
StackOverflowNewbie
  • 35,023
  • 98
  • 252
  • 421
71
votes
14 answers

Header and footer in CodeIgniter

I really don't enjoy writing in every controller: $this->load->view('templates/header'); $this->load->view('body'); $this->load->view('templates/footer'); Is it possible to do, that header and footer would be included automatically and…
good_evening
  • 19,773
  • 60
  • 178
  • 288
68
votes
6 answers

Best method of including views within views in CodeIgniter

I'm starting a large codeigniter project and would like to try to create some reusable 'mini' views for snippets of content like loops of data which may be displayed on different pages/controllers. Is it better to call the views from within the main…
David
  • 14,182
  • 34
  • 96
  • 150
67
votes
9 answers

subquery in codeigniter active record

SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace); How do I write the above select statement in CodeIgniter active record?
mardon
  • 1,009
  • 1
  • 11
  • 25