Questions tagged [codeigniter]

CodeIgniter is an Application Development Framework - a toolkit - for people who build websites 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 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 4.2.10 was released on November 5, 2022

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 18.2k stars 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: 4.2.10 (Release Date: November 5, 2022)


Top Tips For Codeigniter

One of the most commonly asked questions in Codeigniter on Stack Overflow is when I view my page and get the error 404 "Page Not Found". It would help if you looked at a couple of solutions before asking the question.

  1. Solution 1: Check the first letter of the class name and filename of the controller and models in 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

69561 questions
98
votes
12 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,882
  • 7
  • 36
  • 61
90
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
  • 89,623
  • 107
  • 270
  • 423
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
  • 13
  • 16
88
votes
6 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
  • 15,157
  • 11
  • 45
  • 60
84
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
  • 89,623
  • 107
  • 270
  • 423
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
  • 30,637
  • 12
  • 78
  • 117
84
votes
9 answers

Sending email with gmail smtp with codeigniter email library

load->library('email'); } function index() { $config['protocol'] = 'smtp'; $config['smtp_host'] =…
NanoBot
  • 837
  • 1
  • 7
  • 10
83
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
  • 39,403
  • 111
  • 277
  • 441
82
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,764
  • 21
  • 52
  • 71
82
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,994
  • 17
  • 70
  • 99
80
votes
11 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,628
  • 11
  • 48
  • 79
77
votes
11 answers

how to get the base url in javascript

I am building a website with CodeIgniter, I have various resources that I load with the base_url helper function like this which produces…
Nehemias Herrera
  • 1,751
  • 1
  • 14
  • 12
76
votes
4 answers

PhpStorm Field accessed via magic method

I have ignited datatables Library in my CodeIgniter library folder. Some Code from Library class Datatables { /** * Global container variables for chained argument results * */ protected $ci; protected $table; …
Sizzling Code
  • 5,932
  • 18
  • 81
  • 138
73
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
  • 16,246
  • 34
  • 103
  • 162
72
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
  • 21,085
  • 65
  • 193
  • 298