Welcome Guest, Not a member yet? Register   Sign In
How do I Migrate from 4.3.x to 4.4.x?
#1

Migrating from 3.x to 4.x required me to practically rewrite most of the code in my project because it was almost like changing languages. It seems this may be is the case for moving to 4.4.x from 4.3.x. I have looked at https://codeigniter.com/user_guide/insta...e_440.html but I cant understand much.
I looked at the https://www.codeigniter.com/user_guide/t...pages.html and found that
$routes->get('pages', 'Pages::index');
now becomes
$routes->get('pages', [Pages::class, 'index']);
and realised that controllers no longer use 'echo' to spew views. Instead they use 'return'.
Is it possible to get a list of all the things that must be changed for migration?
Reply
#2

(This post was last modified: 09-30-2023, 02:47 AM by JustJohnQ.)

EDIT: I misread you message and thought you were trying to upgrade from 3.x to the latest version 4.x

Check Kenjis contribution:
https://forum.codeigniter.com/thread-78565.html
Check this Codeigniter upgrade guide:
https://codeigniter.com/user_guide/insta...e_4xx.html
Reply
#3

(This post was last modified: 09-30-2023, 04:27 AM by ozornick.)

https://www.codeigniter.com/user_guide/i...ting-rules

The routing has not changed, you can use old variant:
PHP Code:
$routes->get('pages''Pages::index'); 


See https://github.com/codeigniter4/CodeIgniter4/pull/5854

Yes, "return" is better because the framework has a Response class. Instant display is a bad way
Reply
#4

It is a new feature in v4.2.0. If you use IDE, you can jump to the controller from the route file.
See https://www.codeigniter.com/user_guide/i...ble-syntax
And you can still use the old style.
Reply
#5

(09-30-2023, 01:27 AM)owino Wrote: It seems this may be is the case for moving to 4.4.x from 4.3.x. I have looked at https://codeigniter.com/user_guide/insta...e_440.html but I cant understand much.

When you upgrade from 4.3.x, you need to check the related all version upgrading guides.
https://www.codeigniter.com/user_guide/i...ading.html
If you upgrade from 4.3.7, check:
https://www.codeigniter.com/user_guide/i...e_438.html
and https://www.codeigniter.com/user_guide/i...e_440.html

And it is better to check the related all changelogs:
https://www.codeigniter.com/user_guide/c...index.html
Reply
#6

Here is a list of some of the major changes that you will need to make when migrating from CodeIgniter 4.3.x to 4.4.x:

Controllers no longer use echo to spew views. Instead they use return.
This means that you will need to change all of your controller methods that currently use echo to return the view instead. For example:

PHP
// CodeIgniter 4.3.x
public function index()
{
echo view('pages/index');
}

// CodeIgniter 4.4.x
public function index()
{
return view('pages/index');
}
The $routes array now uses PHP 8.1 named arguments.
This means that you will need to change all of your $routes array definitions to use named arguments instead of positional arguments. For example:

PHP
// CodeIgniter 4.3.x
$routes->get('pages/index', 'Pages::index');

// CodeIgniter 4.4.x
$routes->get('pages/index', [Pages::class, 'index']);

The Database::connect() method now returns a ConnectionPool object.
This means that you will need to change all of your code that currently uses the Database::connect() method to return the ConnectionPool object instead. For example:

PHP
// CodeIgniter 4.3.x
$db = Database::connect();

// CodeIgniter 4.4.x
$db = Database::connect()->getConnection('default');
The Validation::check() method now accepts a string or array of validation rules as its second argument.
This means that you will need to change all of your code that currently uses the Validation::check() method to accept a string or array of validation rules as its second argument instead of a single validation rule. For example:

PHP
// CodeIgniter 4.3.x
$validation->check($input, 'required');

// CodeIgniter 4.4.x
$validation->check($input, ['required', 'min_length' => 5]);
The Security::encrypt() and Security::decrypt() methods now accept a string or array of data as their first argument.
This means that you will need to change all of your code that currently uses the Security::encrypt() and Security::decrypt() methods to accept a string or array of data as their first argument instead of a single piece of data. For example:

PHP
// CodeIgniter 4.3.x
$encryptedData = Security::encrypt($data);

// CodeIgniter 4.4.x
$encryptedData = Security::encrypt(['data' => $data]);
These are just some of the major changes that you will need to make when migrating from CodeIgniter 4.3.x to 4.4.x. For a more comprehensive list of changes, please consult the CodeIgniter 4.4 upgrade guide.

I hope this helps!
Reply
#7

(This post was last modified: 10-27-2023, 02:52 PM by kenjis.)

These are all incorrect. Are you a LLM?

(10-27-2023, 04:32 AM)AnanayKayar Wrote: Here is a list of some of the major changes that you will need to make when migrating from CodeIgniter 4.3.x to 4.4.x:

Controllers no longer use echo to spew views. Instead they use return.
This means that you will need to change all of your controller methods that currently use echo to return the view instead. For example:

PHP
// CodeIgniter 4.3.x
public function index()
{
    echo view('pages/index');
}

// CodeIgniter 4.4.x
public function index()
{
    return view('pages/index');
}

(10-27-2023, 04:32 AM)AnanayKayar Wrote: The $routes array now uses PHP 8.1 named arguments.
This means that you will need to change all of your $routes array definitions to use named arguments instead of positional arguments. For example:

PHP
// CodeIgniter 4.3.x
$routes->get('pages/index', 'Pages::index');

// CodeIgniter 4.4.x
$routes->get('pages/index', [Pages::class, 'index']);

(10-27-2023, 04:32 AM)AnanayKayar Wrote: The Database::connect() method now returns a ConnectionPool object.
This means that you will need to change all of your code that currently uses the Database::connect() method to return the ConnectionPool object instead. For example:

PHP
// CodeIgniter 4.3.x
$db = Database::connect();

// CodeIgniter 4.4.x
$db = Database::connect()->getConnection('default');

(10-27-2023, 04:32 AM)AnanayKayar Wrote: The Validation::check() method now accepts a string or array of validation rules as its second argument.
This means that you will need to change all of your code that currently uses the Validation::check() method to accept a string or array of validation rules as its second argument instead of a single validation rule. For example:

PHP
// CodeIgniter 4.3.x
$validation->check($input, 'required');

// CodeIgniter 4.4.x
$validation->check($input, ['required', 'min_length' => 5]);

(10-27-2023, 04:32 AM)AnanayKayar Wrote: The Security::encrypt() and Security::decrypt() methods now accept a string or array of data as their first argument.
This means that you will need to change all of your code that currently uses the Security::encrypt() and Security::decrypt() methods to accept a string or array of data as their first argument instead of a single piece of data. For example:

PHP
// CodeIgniter 4.3.x
$encryptedData = Security::encrypt($data);

// CodeIgniter 4.4.x
$encryptedData = Security::encrypt(['data' => $data]);
These are just some of the major changes that you will need to make when migrating from CodeIgniter 4.3.x to 4.4.x. For a more comprehensive list of changes, please consult the CodeIgniter 4.4 upgrade guide.

I hope this helps!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB