CodeIgniter 4 is a rewrite of the framework, and is not backwards compatible. It is more appropriate to think of converting your app, rather than upgrading it. Once you have done that, upgrading from one version of CodeIgniter 4 to the next will be straightforward.

The "lean, mean and simple" philosophy has been retained, but the implementation has a lot of differences, compared to CodeIgniter 3.

There is no 12-step checklist for upgrading. Instead, start with a copy of CodeIgniter 4 in a new project folder, however you wish to install and use it, and then convert and integrate your app components. We'll try to point out the most important considerations here.

Not all of the CI3 libraries have been ported or rewritten for CI4! See the threads in the CodeIgniter 4 Roadmap subforum for an uptodate list!

Do read the user guide before embarking on a project conversion!

Downloads

  • CI4 is still available as a ready-to-run zip or tarball, which includes the user guide (though in the docs subfolder
  • It can also be installed using Composer

Namespaces

  • CI4 is built for PHP7.1+, and everything in the framework is namespaced, even the helpers

Application Structure

  • The framework still has application and system folders, with the same interpretation as before
  • The framework now provides for a public folder, intended as the document root for your app
  • There is also a writable folder, to hold cache data, logs, and session data
  • The application folder looks very similar to that for CI3, with some name changes, and some subfolders moved to the writable folder
  • There is no longer a nested application/core folder, as we have a different mechanism for extending framework components (see below)

Class loading

  • There is no longer a CodeIgniter "superobject", with framework component references magically injected as properties of your controller
  • Classes are instantiated where needed, and components are managed by Services
  • The class loader automatically handles PSR4 style class locating, within the App (application) and CodeIgniter (i.e. system) top level namespaces; with composer autoloading support, and even using educated guessing to find your models and libraries if they are in the right folder even though not namespaced
  • You can configure the class loading to support whatever application structure you are most comfortable with, including the "HMVC" style

Controllers

  • Controllers extend CodeIgniterController instead of CI_Controller
  • They don't use a constructor any more (to invoke CI "magic") unless that is part of a base controller you make
  • CI provides Request and Response objects for you to work with - more powerful than the CI3-way
  • If you want a base controller (MY_Controller in CI3), make it where you like, e.g. BaseController extends Controller, and then have your controllers extend it

Models

  • Models extend CodeIgniterModel instead of CI_Model
  • The CI4 model has much more functionality, including automatic database connection, basic CRUD, in-model validation, and automatic pagination
  • CI4 also has the Entity class you can build on, for richer data mapping to your database tables
  • Instead of CI3's $this->load->model(x);, you would now use $this->x = new X();, following namespaced conventions for your component

Views

  • Your views look much like before, but they are invoked differently ... instead of CI3's $this->load->view(x); you can use echo view(x);
  • CI4 supports view "cells", to build your response in pieces
  • The template parser is still there, but substantially enhanced

Libraries

  • Your app classes can still go inside application\Libraries, but they don't have to
  • Instead of CI3's $this->load->library(x); you can now use $this->x = new X();, following namespaced conventions for your component

Helpers

  • Helpers are pretty much the same as before, though some have been simplified

Extending the framework

  • You don't need a core folder to hold MY_... framework component extensions or replacements
  • You don't need MY_x classes inside your libraries folder to extend or replace CI4 pieces
  • Make any such classes where you like, and add appropriate service methods in application/Config/Services.php to load your components instead of the default ones

[codeigniter4]Upgrading from 3.x to 4.x的更多相关文章

  1. VS2013: upgrading a Windows Phone 7/8 and Windows 8 apps(转)

    VS2013: upgrading a Windows Phone 7/8 and Windows 8 apps September 17, 2013Windows 8, Windows PhoneJ ...

  2. Installation and Upgrading

    Cumulative Feature Overview Identifies product features available to you when upgrading. This tool r ...

  3. Upgrading or Redeploying SharePoint 2010 Workflows

    While creating several State Machine SharePoint 2010 workflows using visual studio for a client I ha ...

  4. Upgrading Applications

    Upgrading Applications If you have an existing Zend Framework v2 application, and want to update it ...

  5. Pycharm 中You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    今天运行程序的时候出现了: You are using pip version 10.0.1, however version 18.1 is available.You should conside ...

  6. AIM Tech Round 4 (Div. 1) C - Upgrading Tree 构造 + 树的重心

    C - Upgrading Tree 我发现我构造题好弱啊啊啊. 很明显能想到先找到重心, 然后我们的目标就是把所有点接到重心的儿子上,让重心的儿子子树变成菊花图, 这个先把重心到儿子的边连到 i , ...

  7. [转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse & Generic Unit of Work Repository Framework v2.0

    本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the . ...

  8. Upgrading Elasticsearch

    Upgrading Elasticsearch | Elasticsearch Reference [5.6] | Elastic https://www.elastic.co/guide/en/el ...

  9. 官方文档 Upgrading Elasticsearch

    Upgrading Elasticsearch Before upgrading Elasticsearch: Consult the breaking changes docs. Use the E ...

随机推荐

  1. IBM x3250m5安装redhat 6.5 加载raid卡驱动

    原文地址:http://www.i5i6.net/post/118.html 1. 下载对应raid卡驱动 for redhat6.5 x64(如本次x3250 m5 c100阵列卡驱动 lsi_dd ...

  2. 多柱汉诺塔问题“通解”——c++

    多柱汉诺塔问题 绪言 有位同学看到了我的初赛模拟卷上有一道关于汉诺塔的数学题.大概就是要求4柱20盘的最小移动次数. 他的数学很不错,找到了应该怎样推. 如果要把n个盘子移到另一个柱子上,步骤如下: ...

  3. 第2章 在 HTML中 使用 JavaScript

    第2章 在 HTML中 使用 JavaScript 2.1 script 元素 2.1.1 标签的位置 2.1.2 延迟脚本 2.1.3 异步脚本 2.1.4 在XHTML中的使用 2.1.5 不推荐 ...

  4. .Net框架的模块代码生成器--其一(dotnet new)

    小白教程声明,首先先介绍一下.Net 框架及模块是什么情况: 1.公司的大佬会把框架的代码打包成Nuget包放在公司的服务器上 2.公司会专门开一个git仓库,存储模块的代码,每个模块都有其独立的文件 ...

  5. MySQL表名大小写敏感性

    Linux版MySQL 库名与表名是严格区分大小写的: 表的别名是严格区分大小写的: 列名与列的别名在所有的情况下均是忽略大小写的: 变量名也是严格区分大小写的: 修改步骤如下: 1. 编辑[/etc ...

  6. select下拉框相关操作(更新中。。。)

    背景 记录一些关于html标签的操作,基本上都是jquery操作 select下拉框 根据value查找对应option,然后执行选中操作 $("#selectId").find( ...

  7. 剑指offer-基础练习-增删节点-链表

    /* 链表基本操作: 插入节点和删除节点 */ /* 思路: 使用指向链表的头指针,这样在新插入节点后,头指针不会改变 */ struct ListNode{ int value; ListNode* ...

  8. USB闪存驱动器未显示在MacOS的Finder或磁盘工具上?为什么Mac无法识别USB该如何解决?

    您可能会在Mac上无法显示的闪存驱动器上形成困扰.您确定驱动器正常,但Mac计算机无法检测到.  阅读这篇文章,闪存驱动器未显示在MacOS的Finder或磁盘工具上?为什么Mac无法识别USB该如何 ...

  9. 2020牛客寒假算法基础集训营4-D子段异或

    思路 CODE #include <bits/stdc++.h> #define dbg(x) cout << #x << "=" <&l ...

  10. LED Candle Light Factory-LED Candle Light: Full Of Romance

    LED candle lights are beautiful and can add elegance and romance to any space. These candles make th ...