[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 ...
随机推荐
- ansible基本使用(一)
ansible是什么? ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量 ...
- JAVA面向对象 - 方法重载与覆盖
方法重载 方法重载就是在类的同种实现方式,到底采用哪种方式,取决与调用者给出的参数.方法重载特点是方法名相同,方法的参数类型,个数,顺序至少有一项不同,方法返回类型可以不同,方法的修饰符可以不同,只是 ...
- 1-2.Kubectl命令行工具
1.kubectl用法 $~: kubectl [command] [TYPE] [NAME] [flags] [command] 子命令.用于操作Kubernetes集群资源对象. 可取值:[cre ...
- Win10查看屏保的所在位置
路径 C:\Users\Hlzy\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\Local ...
- nginx解决服务器宕机、解决跨域问题、配置防盗链、防止DDOS流量攻击
解决服务器宕机 配置nginx.cfg配置文件,在映射拦截地址中加入代理地址响应方案 location / { proxy_connect_timeout 1; proxy_send_timeout ...
- 查看appium参数
首先打开appium server并运行,然后将手机与电脑相连,然后在python中写代码,但是代码需要出入appium参数,这些参数怎么查询呢? 1.创建appium参数 { "platf ...
- C++ STL:next_permutation和prev_permutation
两个函数都在#include <algorithm>里 顾名思义,next_permutation用来求下一个排列,prev_permutation用来求上一个排列. 当前的排列不满足函数 ...
- Selenium3+python自动化014-自动化测试框架的作用
1.能够有效组织和管理测试脚本 2.进行数据驱动或者关键字驱动的测试 3.将基础的测试代码进行封装,降低测试脚本编写的复杂性和重复性 4.提高测试脚本维护和修改的效率 5.自动执行测试脚本,并自动发布 ...
- rtp传输h264
---恢复内容开始--- 基本概念的理解 H.264的主要目标:1.高的视频压缩比2.良好的网络亲和性 解决方案:VCL video coding layer 视频编码层NAL network abs ...
- c语言中 char* 和 unsigned char* 的区别浅析(转)
原文:https://blog.csdn.net/guotianqing/article/details/77341657 背景最近在项目中遇到了一个编译警告,是因为定义的变量为char[],而在使用 ...