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
397
votes
11 answers

How should I choose an authentication library for CodeIgniter?

I see there are a few. Which ones are maintained and easy to use? What are their pros and cons?
GavinR
  • 6,094
  • 7
  • 33
  • 44
245
votes
7 answers

Which version of CodeIgniter am I currently using?

Quick question. Is there something similar to a phpinfo() - that would display the version for CodeIgniter? Thanks.
Dirk
  • 6,774
  • 14
  • 51
  • 73
190
votes
7 answers

CodeIgniter: Create new helper?

I need to loop lot of arrays in different ways and display it in a page. The arrays are generated by a module class. I know that its better not to include functions on 'views' and I want to know where to insert the functions file. I know I can…
Jonathan
  • 8,676
  • 20
  • 71
  • 101
181
votes
3 answers

Only variable references should be returned by reference - Codeigniter

After the server PHP upgrade I am getting the following error with PHP Version 5.6.2 on Apache 2.0 A PHP Error was encountered Severity: Notice Message: Only variable references should be returned by reference Filename: core/Common.php Line Number:…
Techie
  • 44,706
  • 42
  • 157
  • 243
179
votes
10 answers

how to get last insert id after insert query in codeigniter active record

I have an insert query (active record style) used to insert the form fields into a MySQL table. I want to get the last auto-incremented id for the insert operation as the return value of my query but I have some problems with it. Inside the…
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
176
votes
35 answers

CodeIgniter removing index.php from url

My current urls look like this [mysite]index.php/[rest of the slug]. I want to strip index.php from these urls. mod_rewrite is enabled on my apache2 server. In config, $config['index_page'] = ''; My codeignitor root .htaccess file contains,…
Nihar Sarangi
  • 4,845
  • 8
  • 27
  • 32
154
votes
11 answers

CodeIgniter activerecord, retrieve last insert id?

Are there any options to get the last insert id of a new record in CodeIgniter? $last_id = $this->db->insert('tablename', array('firstcolumn' => 'value', 'secondcolumn' => 'value') ); Considering the table consits of fields id…
DDecoene
  • 7,184
  • 7
  • 30
  • 43
146
votes
14 answers

Where do I put image files, css, js, etc. in Codeigniter?

Where is it acceptable to put css folders and image file folders? I was thinking inside the view folder? However the controller always reroutes the path to the base url so I have to specify the path in the .html file to where it sits, which is…
triq
  • 1,967
  • 5
  • 23
  • 24
137
votes
14 answers

How to insert multiple rows from array using CodeIgniter framework?

I'm passing a large dataset into a MySQL table via PHP using insert commands and I'm wondering if it's possible to insert approximately 1000 rows at a time via a query other than appending each value on the end of a mile-long string and then…
toofarsideways
  • 3,956
  • 2
  • 31
  • 51
128
votes
16 answers

How to print SQL statement in codeigniter model

I have a sql statement in my model, I then say $query = $this->db->query($sql, array(fields, fields1); if ($query) { return true: } else { echo "failed"; return false; } My query always fails, how do I get php to print the exact sql…
Technupe
  • 4,831
  • 14
  • 34
  • 37
125
votes
11 answers

CodeIgniter: How to get Controller, Action, URL information

I have these URLs: http://backend.domain.com/system/setting/edit/12 http://backend.domain.com/product/edit/1 How to get controller name, action name from these URLs. I'm CodeIgniter newbie. Are there any helper function to get this…
noname.cs
  • 1,938
  • 4
  • 16
  • 25
117
votes
10 answers

PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI

I am building a PHP application in CodeIgniter. CodeIgniter sends all requests to the main controller: index.php. However, I don't like to see index.php in the URI. For example, http://www.example.com/faq/whatever will route to…
Eli
  • 97,462
  • 20
  • 76
  • 81
116
votes
27 answers

How to remove "index.php" in codeigniter's path

How do I remove the "index.php" sticking out in every path in codeigniter somewhere in the center? I want clean non index.php-fied URLs?
OrangeRind
  • 4,798
  • 13
  • 45
  • 57
110
votes
11 answers

CodeIgniter - accessing $config variable in view

Pretty often I need to access $config variables in views. I know I can pass them from controller to load->view(). But it seems excessive to do it explicitly. Is there some way or trick to access $config variable from CI views without disturbing…
AlexA
  • 4,028
  • 8
  • 51
  • 84
108
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
  • 9,598
  • 15
  • 48
  • 67
1
2 3
99 100