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
70
votes
3 answers

Destroying a specific session in Code Igniter

I want to be able to log users out of my app built in Code Igniter. I know how to end an active local session: $this->session->sess_destroy(); But how can I destroy a session that was started on another computer and thereby log a user out of their…
frosty
  • 4,741
  • 4
  • 17
  • 9
70
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,065
  • 1
  • 11
  • 29
69
votes
5 answers

Redirect with CodeIgniter

Can anyone tell me why my redirect helper does not work the way I'd expect it to? I'm trying to redirect to the index method of my main controller, but it takes me www.example.com/index/provider1/ when it should route to www.example.com/provider1.…
ocergynohtna
  • 1,703
  • 2
  • 21
  • 29
69
votes
9 answers

Directory index forbidden by Options directive

I'm using the dompdf plugin for codeigniter: http://codeigniter.com/wiki/PDF_generation_using_dompdf/ to generate pdfs from a form. This works on localhost, but on the live server I get this in the error log: Directory index forbidden by Options…
logic-unit
  • 4,195
  • 12
  • 47
  • 72
68
votes
12 answers

base_url() function not working in codeigniter

In my web application using codeigniter. I am trying to use base_url() function but it shows empty results. I have also used autoload helper through autoload file, but then too it doesn't seem to work. Also I had defined base constants but all in…
Sanks R
  • 895
  • 1
  • 11
  • 17
67
votes
8 answers

Codeigniter - multiple database connections

I have to retrieve a MySQL database information from master database and then connect to that database, and fetch some records. I mean that holding one database I want to load another database. Is it possible with Codeigniter? Right now I'm using…
Sadaf Sid
  • 1,510
  • 3
  • 17
  • 30
67
votes
1 answer

Advantages / Disadvantages of pconnect option in CodeIgniter

One of the parameters in the CodeIgniter database config is the following ['pconnect'] TRUE/FALSE - Whether to use a persistent connection What do you recommend I set this to? Is there a significant performance hit if I set it to FALSE? What…
Clayton
  • 6,089
  • 10
  • 44
  • 47
66
votes
5 answers

What is a slug?

I'm currently working through CodeIgniters tutorial in its fantastic documentation. However there is a term that is frequently used and it's called a "slug". I've looked around a lot to find out what the term means and I can't make sense of what it…
mzyrc
  • 784
  • 1
  • 7
  • 18
65
votes
5 answers

How to add an ORDER BY clause using CodeIgniter's Active Record methods?

I have a very small script to get all records from a database table, the code is below. $query = $this->db->get($this->table_name); return $query->result(); Using this syntax, how would I add a ORDER BY 'name' clause to my select query? I get…
Cecil
  • 1,609
  • 5
  • 21
  • 26
64
votes
11 answers

CodeIgniter Active Record - Get number of returned rows

I'm very new to CodeIgniter and Active Record in particular, I know how to do this well in normal SQL but I'm trying to learn. How can I select some data from one of my tables, and then count how many rows are returned using CodeIgniters Active…
Zim
  • 5,403
  • 7
  • 27
  • 19
63
votes
3 answers

Increment field of mysql database using codeigniter's active record syntax

I have the following php-codeigniter script which attempts to increment a field of a record using active-record syntax: $data = array('votes' => '(votes + 1)'); $this->db->where('id', $post['identifier']); $this->db->update('users', $data); This…
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
63
votes
12 answers

Does CodeIgniter automatically prevent SQL injection?

I just inherited a project because the last developer left. The project is built off of Code Igniter. I've never worked with Code Igniter before. I took a quick look at the code and I see database calls in the controller like this: $dbResult =…
John
  • 32,403
  • 80
  • 251
  • 422
63
votes
6 answers

Upstream too big - nginx + codeigniter

I am getting this error from Nginx, but can't seem to figure it out! I am using codeigniter and am using the database for sessions. So I'm wondering how the header can ever be too big. Is there anyway to check what the header is? or potentially see…
Aram Papazian
  • 2,453
  • 6
  • 38
  • 45
62
votes
9 answers

Convert string to ObjectID in MongoDB

I am developing an API using Codeigniter and MongoDB. In some parts of the database I have saved the ID of an image in ObjectID format instead of a string. Now I got an ID in string format and I need to query the database using it. How can I…
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175
61
votes
2 answers

How do I use PHPUnit with CodeIgniter?

I have read and read articles on PHPUnit, SimpleTest, and other Unit Testing frameworks. They all sound so great! I finally got PHPUnit working with Codeigniter thanks to https://bitbucket.org/kenjis/my-ciunit/overview Now my question is, how do I…
zechdc
  • 3,374
  • 9
  • 40
  • 52