[codeigniter4]Upgrading from 3.x to 4.x
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
applicationandsystemfolders, with the same interpretation as before - The framework now provides for a
publicfolder, intended as the document root for your app - There is also a
writablefolder, to hold cache data, logs, and session data - The
applicationfolder looks very similar to that for CI3, with some name changes, and some subfolders moved to thewritablefolder - There is no longer a nested
application/corefolder, 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) andCodeIgniter(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
RequestandResponseobjects 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
Entityclass 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 useecho 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
corefolder to holdMY_...framework component extensions or replacements - You don't need
MY_xclasses 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.phpto load your components instead of the default ones
[codeigniter4]Upgrading from 3.x to 4.x的更多相关文章
- 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 ...
- Installation and Upgrading
Cumulative Feature Overview Identifies product features available to you when upgrading. This tool r ...
- Upgrading or Redeploying SharePoint 2010 Workflows
While creating several State Machine SharePoint 2010 workflows using visual studio for a client I ha ...
- Upgrading Applications
Upgrading Applications If you have an existing Zend Framework v2 application, and want to update it ...
- 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 ...
- AIM Tech Round 4 (Div. 1) C - Upgrading Tree 构造 + 树的重心
C - Upgrading Tree 我发现我构造题好弱啊啊啊. 很明显能想到先找到重心, 然后我们的目标就是把所有点接到重心的儿子上,让重心的儿子子树变成菊花图, 这个先把重心到儿子的边连到 i , ...
- [转]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 . ...
- Upgrading Elasticsearch
Upgrading Elasticsearch | Elasticsearch Reference [5.6] | Elastic https://www.elastic.co/guide/en/el ...
- 官方文档 Upgrading Elasticsearch
Upgrading Elasticsearch Before upgrading Elasticsearch: Consult the breaking changes docs. Use the E ...
随机推荐
- Bringing up interface eth0: Device eth0 does not seem to be presen
在公司的电脑虚拟机上安装了centos 6.5 ,然后我把他克隆下来用在家里电脑的虚拟机上,打开后查看ip,发现只有回环地址lo,没有eth0, 于是重启网络 输入 service network r ...
- 记录zabbix4.0升级4.2
系统环境 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.9 (Final) 官方网站 官方文档升级其实很简单如果 ...
- Node.js核心模块-net
net.Socket 类 socket.remotePort 访问服务器的远程端口 const http = require('http'); const server = http.createSe ...
- AGC011-E Increasing Numbers
题意 给定一个数\(n\),\(n≤10^{500,000}\),问\(n\)最少可以拆分成几个不降数的和.一个不降数是在十进制位下,从高位往低位看,每个数都不会比高位的数更小的数 做法 不降数可以拆 ...
- AGC011-C Squared Graph
题意 给定一个\(n\)个点\(m\)条边的图,构建一个\(n^2\)个点的图,新图的每个点都可以看成一个二元组,新图上的点\((a,b)和(a′,b′)\)之间有边,当且仅当原图中\((a,a′), ...
- QingTing.Fm-WPF是调用蜻蜓FMAPI 查询API内容展示,进行播放
QingTing.Fm 是调用蜻蜓FM API 查询界面内容,进行在线播放. Release地址下载 环境 Visual Studio 2019,dotNet Framework 4.6.1 SD ...
- shiro权限认证Realm的四大用法
一.SimpleAccountRealm public class AuthenticationTest { SimpleAccountRealm sar=new SimpleAcc ...
- Wannafly Winter Camp 2020 Day 7E 上升下降子序列 - 数学
神奇公式 #include <bits/stdc++.h> using namespace std; #define int long long int n,mod,c[205][205] ...
- Spring MVC 定时任务注解说明
一.注解说明. Spring 自带的定时任务执行@Scheduled注解,可以定时的.周期性的执行一些任务.查看@Scheduled的注解可以看到有以下三种: 1.1 String cron() de ...
- python 3.6 安装 opencv 3.4
一种说法是,到opencv官网下载相应的版本opencv,解压,把cv2.pyd放到 python安装文件夹下的\Lib\site-packages里即可, 此时import cv2即可成功 我的没有 ...