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. vuex目录配置

    vuex目录配置,即vue-cli开发时目录配置 项目结构 Vuex 并不限制你的代码结构.但是,它规定了一些需要遵守的规则: 应用层级的状态应该集中到单个 store 对象中. 提交 mutatio ...

  2. em和rem区别

    em大小依据父元素的字体大小的倍数 rem大小依据与根元素,即html标签的font-size大小

  3. .NET Core DI简单介绍

    依赖注入的基础 我们都知道DI,,他是一种开发模式.他是将服务可被应用程序任何位置的代码使用,当某个代码组件(如一个类)需要引用某些外部代码(一个服务)时.都有两种选择 1:直接在调用代码种创建服务组 ...

  4. generalization error

    泛化误差 机器学习中的Bias(偏差),Error(误差),和Variance(方差)有什么区别和联系? 准与确的关系 bias 偏差:模型越复杂,模型的偏差越小,方差越小,因此会出现overfitt ...

  5. python报错bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

    qpython运行 原代码:    soup = BeautifulSoup(r.text,'lxml') 报错:bs4.FeatureNotFound: Couldn't find a tree b ...

  6. 关于Dijk采访的一些感想

    有效的程序员不应该浪费很多时间用于程序调试,他们应该一开始就不要把故障引入! 反复,一遍又一遍的尝试,真的会让人心烦,对于有的问题解决不了,其实有很多原因,写出来的程序其实是非常考验人的细节处理能力的 ...

  7. luoguP5219 无聊的水题 I 多项式快速幂

    有一个幼儿园容斥:最大次数恰好为 $m=$  最大次数最多为 $m$ - 最大次数最多为 $m-1$. 然后来一个多项式快速幂就好了. code: #include <cmath> #in ...

  8. cc.fade.fade

    用cc.fadeIn之前要先把setOpacity(0),笑哭,啊啊啊啊啊.因为这个东西卡了好久,啊啊啊

  9. 关于Swagger会报AbstractSerializableParameter类的异常问题

    SpringBoot-2.2.1.RELEASE 集成 swagger-ui-2.9.2 时,每次在访问到页面时总是报AbstractSerializableParameter类的异常错误,大概内容如 ...

  10. StarUML 2下载、安装、破解全过程

      StarUML官方下载地址:  http://staruml.io/download 破解: ​  1.使用Editplus或者Notepad++等特殊的文本编辑器打开 安装位置下/www/lic ...