[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
application
andsystem
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 thewritable
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) 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
Request
andResponse
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 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
core
folder to holdMY_...
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的更多相关文章
- 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 ...
随机推荐
- 没有正确配置扫描包,提示spring的bean不存在
如下提示的解决方案: <!-- 扫描org.infor包下面的java文件,有Spring的相关注解的类,则把这些类注册为Spring的bean --> <context:comp ...
- Map的底层实现原理
一,前言 1.1,概述 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等,这种一一对应的关系,就叫做映射(K-V).Java提供了专门的集合类用 ...
- 解决jmeter5.1高版本linux CPU,IO,Memory监控性能测试 java.lang.NoSuchMethodError: org.apache.jmeter.samplers.SampleSaveConfiguration.setFormatter(Ljava/t
jmeter中也可以监控服务器的CPU和内存使用情况,但是需要安装一些插件还需要在被监测服务器上开启服务. 安装性能监控插件(jmeter-plugins)后报如下错误,是由于jmeter版本过高jm ...
- 两种从 TensorFlow 的 checkpoint生成 frozenpb 的方法
1. 从 ckpt-.data,ckpt-.index 和 .meta 生成 frozenpb import os import tensorflow as tf from tensorflow.py ...
- Docker Compose 启动mysql,redis,rabbitmq
这里使用的centos7,首先切换到root. sudo -s 首先去设置下载镜像,否则下载这三个东西要很久,而且可能失败. vim /etc/docker/daemon.json 内容如下: { & ...
- P4197 Peaks [克鲁斯卡尔重构树 + 主席树][克鲁斯卡尔重构树学习笔记]
Problem 在\(Bytemountains\)有\(n\)座山峰,每座山峰有他的高度\(h_i\) .有些山峰之间有双向道路相连,共\(M\)条路径,每条路径有一个困难值,这个值越大表示越难走, ...
- CF594D REQ [离线+树状数组,欧拉函数]
设 \[x = \prod_{i=1}^{cnt} p_i^{k_i} [p_i\in prime]\] 那么显然 \[\varphi(x) = x*\frac{1} {\prod_{i=1}^{cn ...
- 如何在Mac上显示和查看隐藏的文件/文件夹
今天的文章推出的是如何在Mac上显示和查看隐藏的文件/文件夹.出于隐私或安全性考虑,出于多种原因,我们需要在Mac计算机上隐藏某些文件.这些文件或文件夹在默认情况下是为Mac的平稳运行而隐藏的,但是如 ...
- 在Windows7中的各种显示模式中桌面图标的尺寸
在Windows7中的各种显示模式中,图标的尺寸 window7 桌面icon设计尺寸大小桌面图标设计尺寸一般是多少超大图标:256X256大图标:128X128中图标:32X32平铺:32X32列表 ...
- MySQL 8 mysql system schema
在大的分类上:mysql schema包括存储数据库对象元数据的数据字典表和用于其他操作目的的系统表 数据字典表和系统表一般使用InnoDB存储引擎 与之前的版本不同,数据字典表和系统表存储在数据目录 ...