This guide covers upgrading to this maintenance fork, which is based on the unreleased CodeIgniter 3.2.0-dev. Many unnecessary breaking changes from 3.2.0-dev have been reverted to preserve backward compatibility. This is the same guide whether you are coming from 3.1.x or 3.2-dev.
Before performing an update you should take your site offline by replacing the index.php file with a static one.
Install via Composer (recommended):
composer require pocketarc/codeigniter
Then update the $system_path in your index.php:
$system_path = 'vendor/pocketarc/codeigniter/system';
Alternatively, you can manually replace all files and directories in your system/ directory.
Note
If you have any custom developed files in these directories, please make copies of them first.
This fork supports PHP 5.4 through 8.5+. We recommend running a currently supported PHP version (8.4 or newer).
The class constructor for CI_Model never contained vital code or useful
logic, only a single line to log a message. A change in CodeIgniter 3.1.7
moved this log message elsewhere and that naturally made the constructor
completely unnecessary.
The constructor is kept as an empty method for backwards compatibility, so
existing code calling parent::__construct() will continue to work.
However, such calls are unnecessary and can be safely removed.
"Loading" a database, whether by using the config/autoload.php settings
or manually via calling $this->load->database() or the less-known
DB() function, will now throw a RuntimeException in case of a
failure.
In addition, being unable to set the configured character set is now also considered a connection failure.
Note
This has been the case for most database drivers in the in the past as well (i.e. all but the 'mysql', 'mysqli' and 'postgre' drivers).
What this means is that if you're unable to connect to a database, or have an erroneous character set configured, CodeIgniter will no longer fail silently, but will throw an exception instead.
You may choose to explicitly catch it (and for that purpose you can't use config/autoload.php to load the :doc:`Database Class <../database/index>`)
try
{
$this->load->database();
}
catch (RuntimeException $e)
{
// Handle the failure
}
Or you may leave it to CodeIgniter's default exception handler, which would log the error message and display an error screen if you're running in development mode.
With the above-mentioned changes, the purpose of the db_set_charset()
method would now only be to change the connection character set at runtime.
That doesn't make sense and that's the reason why most database drivers
don't support it at all.
Thus, db_set_charset() is no longer necessary and is removed.
When running a CodeIgniter application from the CLI, the
:doc:`URI Library <../libraries/uri>` will now ignore the
$config['url_suffix'] and $config['permitted_uri_chars']
configuration settings.
These two options don't make sense under the command line (which is why this change was made) and therefore you shouldn't be affected by this, but if you've relied on them for some reason, you'd probably have to make some changes to your code.
The new improvements for the 'redis' and 'memcached' drivers of the :doc:`Cache Library <../libraries/caching>` may require some small adjustments to your configuration values ...
If you're using the 'redis' driver with a UNIX socket connection, you'll
have to move the socket path from $config['socket'] to
$config['host'] instead.
The $config['socket_type'] option is also removed, although that won't
affect your application - it will be ignored and the connection type will
be determined by the format used for $config['host'] instead.
Since 3.2.0, the 'redis' driver's get() returns cached values with their
original PHP types. In 3.1.x, scalars were returned as strings: FALSE
and NULL became '', and 123 became '123'. Update code that
compares get() results with strings to use the original value's type.
A cached FALSE is now indistinguishable from a missing key: both return
FALSE, as with the other cache drivers. If you need to distinguish
them, cache a different value instead.
The 'memcached' will now ignore configurations that don't specify a host
value (previously, it just set the host to the default '127.0.0.1').
Therefore, if you've added a configuration that only sets e.g. a port,
you will now have to explicitly set the host to '127.0.0.1' as well.
The :doc:`Email Library <../libraries/email>` will now by default check the
validity of all e-mail addresses passed to it. This check used to be Off by
default, and required explicitly setting the validate option to TRUE
in order to enable it.
Naturally, a validity check should not result in any problems, but this is technically a backwards-compatibility break and you should check that everything works fine. If something indeed goes wrong with that, please report it as a bug to us, and you can disable the validate option to revert to the old behavior.
The :doc:`HTML Helper <../helpers/html_helper>` function :php:func:`doctype()` used to default to 'xhtml1-strict' (XHTML 1.0 Strict) when no document type was specified. That default value is now changed to 'html5', which obviously stands for the modern HTML 5 standard.
Nothing should be really broken by this change, but if your application relies on the default value, you should double-check it and either explicitly set the desired format, or adapt your front-end to use proper HTML 5 formatting.
The :doc:`Form Helper <../helpers/form_helper>` function
:php:func:`form_upload()` used to have 3 parameters, the second of which
($value) was never used, as it doesn't make sense for an HTML input
tag of the "file" type.
That dead parameter is now removed, and so if you've used the third one
($extra), having code like this:
form_upload('name', 'irrelevant value', $extra);
You should change it to:
form_upload('name', $extra);
The following is a list of functionalities deprecated in previous CodeIgniter versions that have been removed in 3.2+:
$config['allow_get_array'](use$_GET = array();instead)$config['standardize_newlines']$config['rewrite_short_tags'](no impact; irrelevant on PHP 5.4+)- 'sqlite' database driver (no longer shipped with PHP 5.4+; 'sqlite3' is still available)
- The entire Encrypt Library (the newer :doc:`Encryption Library <../libraries/encryption>` is still available; the old Encrypt library depends on MCrypt which was removed from PHP in 7.2)
- The
$img_path,$img_urland$font_pathparameters from :doc:`CAPCHA Helper <../helpers/captcha_helper>` function :php:func:`create_captcha()` (pass as array options instead).
The :doc:`Input Library <../libraries/input>` used to (often
unconditionally) filter and/or sanitize user input in the $_GET,
$_POST and $_COOKIE superglobals.
This was a legacy feature from older times, when things like register_globals and magic_quotes_gpc existed in PHP. It was a necessity back then, but this is no longer the case and reliance on global filters is a bad practice, giving you a false sense of security.
This functionality is now removed, and so if you've relied on it for whatever reasons, you should double-check that you are properly validating all user inputs in your application (as you always should do).
Internal changes to the :doc:`Output Class <../libraries/output>` make it so that if you're using the :doc:`Web Page Caching <../general/caching>` feature, you'll be left with some old, garbage cache files.
That shouldn't be a problem, but you may want to clear them.
The OCI8 :doc:`Database <../database/index>` driver no longer has these two
methods that were specific to it and not present in other database drivers.
The $curs_id property is also removed.
If you were using those, you can create your own cursors via oci_new_cursor()
and the publicly accessible $conn_id.
You can now specify the full log filename via $config['log_filename'].
Add this configuration option to your application/config/config.php,
if you haven't copied the new one over.
The $config['log_file_extension'] option still works as a fallback,
but $config['log_filename'] takes precedence when set.
Filename settings are captured when the logger is constructed. Default
date-based filenames rotate daily, even in long-running processes; custom
filenames remain fixed. The protected $_log_filename property remains
available for subclasses. It holds the custom filename, or an empty string
for automatic naming; _get_log_filename() returns the resolved filename.
Assigning a custom filename prevents automatic rotation.
In 3.1.x, the :doc:`File Helper <../helpers/file_helper>` function :php:func:`get_dir_file_info()` used to key its output by filename. When reading recursively (by passing FALSE as the second parameter), two files with the same name in different sub-folders collided, and only the last one read was kept.
Output is now keyed by each file's path relative to $source_dir:
// A directory containing config.php and cache/config.php
$info = get_dir_file_info('./path/to/directory/', FALSE);
// 3.1.x: array('config.php' => ...)
// now: array('config.php' => ..., 'cache/config.php' => ...)
For a top-level read (the default), a file's relative path is its filename, so those keys are unchanged. Only code that reads recursively and looks up entries by key needs review.
Note
In 3.2-dev, this function was broken and returned entries holding
only a relative_path key, so there is nothing to migrate if you are
coming from there.
These config files have received some updates. Please copy them to application/config/user_agents.php and application/config/mimes.php.
This only affects form fields that receive arrays. If you don't validate array input, you can skip this step.
If you are upgrading from 3.1.x, check validation rules for field names
without brackets, such as tags. Submitted arrays are now set to
NULL in $_POST after a successful run(); 3.1.x kept them in
$_POST. Add is_array to accept and keep the array, or use tags[]
to validate each element.
If you are upgrading from 3.2-dev, check rules that include is_array
for bracketed field names such as items[]. Rules and callbacks now
receive the whole array; previously only the first element was validated
and passed to callbacks. See :ref:`using-arrays-as-field-names`.
If you set $config['cache_path'] without a trailing slash, such as
/var/cache/ci, cached pages are now served. Previously, cache files
were written but never read. This does not affect configurations where
cache_path is empty or already ends with a slash.
Before upgrading, check that pages calling $this->output->cache() do
not include per-user content, such as account details or CSRF tokens.
Cached output can be served to other visitors. See
:doc:`Web Page Caching <../general/caching>`.
The :doc:`CAPTCHA Helper <../helpers/captcha_helper>` function
:php:func:`create_captcha()` now correctly removes expired images from
img_path when it runs. It matches filenames consisting of a 10-digit
timestamp with an optional fractional part (. or , separator),
followed by .png or .jpg (case-insensitive). Keep img_path
dedicated to CAPTCHA images: any matching file is deleted after
expiration seconds (default 7200). Other files are left alone.
If you are upgrading from 3.1.x, check code that assumes JPEG output.
Since 3.2-dev, create_captcha() always writes PNG files; 3.1.x used
JPEG when imagejpeg() was available. Replace filenames built from
$cap['time'] plus .jpg with the returned $cap['filename'],
which contains the exact filename ($cap['time'] plus .png).
Omitting both img_path and img_url returns the image inline as a
data:image/png;base64,... URI again, as described in the CAPTCHA helper
documentation. This mode was added in 3.2-dev in 2017, but a 2020 merge
accidentally disabled it, causing create_captcha() to return FALSE
instead.