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
70,480
questions
397
votes
11
answers
154k
views
How should I choose an authentication library for CodeIgniter? [closed]
I see there are a few. Which ones are maintained and easy to use? What are their pros and cons?
245
votes
7
answers
178k
views
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.
190
votes
7
answers
178k
views
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 ...
181
votes
3
answers
316k
views
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 ...
181
votes
10
answers
575k
views
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 ...
176
votes
35
answers
466k
views
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'] = '';
...
154
votes
11
answers
245k
views
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')...
146
votes
14
answers
142k
views
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 ...
137
votes
14
answers
257k
views
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 ...
130
votes
17
answers
389k
views
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 ...
125
votes
11
answers
221k
views
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 ...
118
votes
10
answers
88k
views
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/...
116
votes
27
answers
128k
views
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?
111
votes
11
answers
153k
views
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 $...
109
votes
6
answers
246k
views
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 ...
101
votes
12
answers
219k
views
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
...
90
votes
6
answers
102k
views
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 ...
89
votes
9
answers
14k
views
Going from a framework to no-framework [closed]
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 ...
88
votes
6
answers
129k
views
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.
<?php
class ...
85
votes
11
answers
280k
views
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]->...
84
votes
12
answers
249k
views
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 '...
84
votes
9
answers
370k
views
Sending email with gmail smtp with codeigniter email library
<?php
class Email extends Controller {
function Email()
{
parent::Controller();
$this->load->library('email');
}
function index()
{
$config['...
84
votes
6
answers
76k
views
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->...
82
votes
11
answers
138k
views
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' => $...
82
votes
11
answers
124k
views
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 ...
80
votes
11
answers
140k
views
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 = $...
80
votes
4
answers
52k
views
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
*
*/
...
78
votes
11
answers
287k
views
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
<link rel="stylesheet" type="text/css" href="'.base_url('assets/css/...
74
votes
3
answers
67k
views
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 ...
73
votes
6
answers
116k
views
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.
...
72
votes
14
answers
148k
views
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 ...
71
votes
9
answers
363k
views
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 ...
70
votes
9
answers
123k
views
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?
69
votes
5
answers
73k
views
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 ...
69
votes
5
answers
429k
views
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/ ...
68
votes
12
answers
391k
views
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....
67
votes
8
answers
165k
views
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 ...
67
votes
1
answer
27k
views
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 ...
65
votes
5
answers
395k
views
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 ...
64
votes
11
answers
195k
views
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 ...
63
votes
7
answers
54k
views
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 ...
63
votes
3
answers
45k
views
Increment field of mysql database using codeigniter's active record syntax [duplicate]
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['...
63
votes
12
answers
92k
views
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 ...
63
votes
10
answers
174k
views
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 ...
61
votes
2
answers
20k
views
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/...
60
votes
14
answers
166k
views
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 ....
60
votes
7
answers
162k
views
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, ...
60
votes
9
answers
179k
views
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
...
59
votes
6
answers
60k
views
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 ...