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
60
votes
7 answers

CodeIgniter Active Record not equal

In CodeIgniter using active record, how do I perform a not equal to in $this->db->where(). For instance: $this->db->where('emailsToCampaigns.campaignId', $campaignId); Will do equal to, but I need not equal to. I have…
matt
  • 601
  • 1
  • 5
  • 3
59
votes
7 answers

get_instance() in Codeigniter: Why assign it to a variable?

In Codeigniter, get_instance() is a globally available function that returns the Controller super-object which contains all the currently loaded classes (it returns the Controller class instance). I'll include the current source code: get_instance()…
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
59
votes
14 answers

How to set time zone in codeigniter?

I am working in a php project using codeigniter. Please advise me what is the global way to set time zone for php and mysql . In which file I can set this. I want to set it without php.ini and .htaccess file. currently I am using this before every…
Vipul sharma
  • 1,245
  • 1
  • 13
  • 33
59
votes
3 answers

Disable PHPStorm new file branding

When I create a new file using PhpStorm it creates it's own comment at the top, this would be fine however when using codeigniter comments using /* */ do not work, anyway to disable this? if not i'm going to have to get a new editor. Here is what I…
JohnBob
  • 691
  • 1
  • 6
  • 5
58
votes
15 answers

CodeIgniter: Unable to connect to your database server using the provided settings Error Message

I have been using CI just fine using the MySQL driver. I want to use the MySQL driver instead, but as soon as I change it (just add the ‘i’ at the end of MySQL, and added the port number) I get the following error message A Database Error…
Onema
  • 7,331
  • 12
  • 66
  • 102
58
votes
9 answers

How to prevent the "Confirm Form Resubmission" dialog?

How do I clean information in a form after submit so that it does not show this error after a page refresh? See image (from chrome): The dialog has the text: The page that you're looking for used information that you entered. Returning to that …
Martin Rose
  • 599
  • 1
  • 4
  • 6
58
votes
7 answers

Find total number of results in mySQL query with offset+limit

I'm doing a pagination feature using Codeigniter but I think this applies to PHP/mySQL coding in general. I am retrieving directory listings using offset and limit depending on how many results I want per page. However to know the total number of…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
58
votes
6 answers

Why is it good save to save sessions in the database?

I have seen that codeigniter have facility to save session values in database. It says saving session in database is good security practice. But I think saving session information in the database helps improve performance. They save only a few…
kiriappa
  • 822
  • 2
  • 7
  • 14
57
votes
8 answers

Object of class stdClass could not be converted to string

I am having a problem with PHP at the moment, I am getting this error, Object of class stdClass could not be converted to string the error occurs when I run this portion of code in my site, function myaccount() { $data['user_data'] =…
sea_1987
  • 2,902
  • 12
  • 44
  • 69
57
votes
5 answers

MongoDB and CodeIgniter

Can anyone assist in pointing me to a tutorial, library, etc. that will allow me to work with MongoDB from CodeIgniter?
IEnumerator
  • 2,960
  • 5
  • 31
  • 33
56
votes
3 answers

Accessing Class Properties with Spaces

stdClass Object ([Sector] => Manufacturing [Date Found] => 2010-05-03 08:15:19) So I can access [Sector] by using $object->Sector but how can I access [Date Found] ?
Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63
55
votes
5 answers

CodeIgniter: How To Do a Select (Distinct Fieldname) MySQL Query

I'm trying to retrieve a count of all unique values in a field. Example SQL: SELECT count(distinct accessid) FROM (`accesslog`) WHERE record = '123' How can I do this kind of query inside of CodeIgniter? I know I can use $this->db->query(), and…
Ian
  • 11,920
  • 27
  • 61
  • 77
55
votes
2 answers

how to know whether key exists in Json string

Possible Duplicate: How to check if an array element exists? apologize if i am wrong,I am new to PHP, Is there any way to find out whether key exists in Json string after decoding using json_decode function in PHP. $json =…
Nishanth
  • 581
  • 1
  • 4
  • 3
54
votes
28 answers

Codeigniter displays a blank page instead of error messages

I'm using Codeigniter, and instead of error messages I'm just getting a blank page. Is there any way to show PHP error messages instead? It's very hard to debug when I get no feedback. My environment is Ubuntu with Apache.
FlyingCat
  • 14,036
  • 36
  • 119
  • 198
51
votes
9 answers

MVC Question: Should I put form validation rules in the controller or model?

On one hand form validation could be seen as part of the application logic and therefore belonging in the model. On the other hand, it deals directly with the input coming from view and handles displaying errors, etc. From that angle it makes more…
Ali
  • 261,656
  • 265
  • 575
  • 769