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

Codeigniter - making my controllers more DRY

In my codeigniter controller function I am using the following code to generate my view and insert all the necessary content: $left_column = $this->load->view('widgets/sub_navigation', $subnav_data, true); $left_column .=…
hairynuggets
  • 3,191
  • 22
  • 55
  • 90
6
votes
5 answers

Working with SQLite in codeigniter

I'm trying to get started with sqlite in the latest version of CodeIgniter. My database.php looks like this: $active_group = 'default'; $active_record = TRUE; $db ['default'] ['hostname'] =''; $db ['default'] ['username'] =''; $db ['default']…
IVar
  • 73
  • 2
  • 4
6
votes
5 answers

Counts on single column for different conditions

I require 3 different counts on single column for different conditions. Table structure: interview- id-int(10) c_id-int(10) experience-varchar2(100) experience have 3 different values- 1)positive 2)negative 3)neutral I require 3 different counts of…
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
6
votes
1 answer

PHP Codeigniter error: call to undefined method ci_db_mysql_driver::result()

I was trying to create an xml response using codeigniter. The following error gets thrown when i run the code. This page contains the following errors: error on line 1 at column 48: Extra content at the end of the document
Ronnie
  • 81
  • 1
  • 1
  • 2
6
votes
2 answers

Pass variables of a function to other function in a controller in codeigniter?

I have a controller that has the next functions: class controller { function __construct(){ } function myfunction(){ //here is my variable $variable="hello" } function myotherfunction(){ //in this…
cabita
  • 832
  • 2
  • 12
  • 36
6
votes
4 answers

Codeigniter - Perform action if database query returns no results

How can I return a value of 'no data found' if my query returns no results??? This is my code: function getTerms($letter) { $this->db->select('term, definition'); $this->db->from('glossary'); $this->db->where(array('letter' =>…
hairynuggets
  • 3,191
  • 22
  • 55
  • 90
6
votes
1 answer

What would my controller be in these scenarios in a mvc web application?

1) Where does the homepage of your website fit into "controllers"? I've seen some people use a "page" controller to handle static pages like, about, home, contact, etc., but to me this doesn't seem like a good idea. Would creating a distinct…
Joe
  • 425
  • 1
  • 5
  • 13
6
votes
1 answer

unsetting some session data in codeigniter

I am saving some data in a session, and certain points in my websites, I am giving the user the option to removes certain parts of the session based on the array key, the array I get when I do, print_r($this->session->userdata('shortlist'); this…
Udders
  • 6,914
  • 24
  • 102
  • 194
6
votes
4 answers

CodeIgniter/PHP/MySQL: Retrieving data with JOIN

I'm new to PHP/MySQL and super-new to CodeIgniter.. I have information in many MySQL tables. I want to retrieve it with JOIN where the tables primary keys are equal to $variable... How can I do it and get all the fields without the primary key…
Jonathan
  • 8,676
  • 20
  • 71
  • 101
6
votes
4 answers

Codeigniter Form Validation: How to redirect to the previous page if found any validation error?

I am using Codeigniter's validation class to validate my form. Could you please tell me how to redirect to the previous page from controller if found any validation error? In my controller: if ($this->form_validation->run() == FALSE){ //****…
black_belt
  • 6,601
  • 36
  • 121
  • 185
6
votes
7 answers

access codeigniter session values from external files

In my codeigniter project i have added KCK finder. it needs some of session values which is controlled by codeigniter. how can i access CI session values from external files ?
balaphp
  • 1,306
  • 5
  • 20
  • 40
6
votes
5 answers

Codeigniter change database config at runtime

Can I change the database config per method in a controller? $db['default']['db_debug'] = TRUE; The default is TRUE, while I need to make it false in a certain method to catch the error and do something else (for example show 404 page). When I…
Henson
  • 5,563
  • 12
  • 46
  • 60
6
votes
9 answers

Do you need to have a very good knowledge of PHP before diving into frameworks (like Zend, CakePHP)?

I'm asking this in comparison with Javascript and jQuery. I was able to learn jQuery with only a basic understanding of Javascript (but I am continually learning Javascript while using jQuery). Is it the same for PHP and its frameworks? Can I start…
catandmouse
  • 11,309
  • 23
  • 92
  • 150
6
votes
5 answers

codeigniter redirect non-www to www

i saw .htaccess Redirect non-WWW to WWW preserving URI string but it doesn't work for me if i go to mysite.com/site/something i get redirected to mysite.com/something RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ RewriteRule (.*)…
braindamage
  • 2,226
  • 4
  • 24
  • 33
6
votes
11 answers

CodeIgniter or PHP Equivalent of Rails Partials and Templates

In CodeIgniter, or core PHP; is there an equivalent of Rails's view partials and templates? A partial would let me render another view fragment inside my view. I could have a common navbar.php view that I could point to the inside my homepage.php…
Wayne Kao
  • 8,125
  • 5
  • 30
  • 25