Skip to content

Commit 9049168

Browse files
authored
Merge pull request #7027 from kenjis/fix-docs-upgrade_4xx
docs: update Upgrading from 3.x to 4.x and MVC
2 parents 94c06b1 + bc2bd33 commit 9049168

8 files changed

Lines changed: 50 additions & 24 deletions

File tree

user_guide_src/source/incoming/controllers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ A Controller is simply a class file that handles a HTTP request. :doc:`URI Routi
1616
Every controller you create should extend ``BaseController`` class.
1717
This class provides several features that are available to all of your controllers.
1818

19+
.. _controller-constructor:
20+
1921
Constructor
2022
***********
2123

user_guide_src/source/installation/upgrade_4xx.rst

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ General Adjustments
3535
Downloads
3636
=========
3737

38-
- CI4 is still available as a ready-to-run zip or tarball.
39-
- It can also be installed using Composer.
38+
- CI4 is still available as a :doc:`ready-to-run zip or tarball <../installation/installing_manual>`.
39+
- It can also be installed using :doc:`Composer <../installation/installing_composer>`.
4040

4141
Namespaces
4242
==========
@@ -90,10 +90,10 @@ Class Loading
9090

9191
- There is no longer a CodeIgniter "superobject", with framework component
9292
references magically injected as properties of your controller.
93-
- Classes are instantiated where needed, and components are managed
94-
by ``Services``.
95-
- The class loader automatically handles PSR-4 style class locating,
96-
within the ``App`` (**app**) and ``CodeIgniter`` (i.e., **system**) top level
93+
- Classes are instantiated where needed, and framework components are managed
94+
by :doc:`../concepts/services`.
95+
- The :doc:`Autoloader <../concepts/autoloader>` automatically handles PSR-4 style class locating,
96+
within the ``App`` (**app** folder) and ``CodeIgniter`` (i.e., **system** folder) top level
9797
namespaces; with Composer autoloading support.
9898
- You can configure the class loading to support whatever application structure
9999
you are most comfortable with, including the "HMVC" style.
@@ -102,21 +102,40 @@ Libraries
102102
=========
103103

104104
- Your app classes can still go inside **app/Libraries**, but they don't have to.
105-
- Instead of CI3's ``$this->load->library(x);`` you can now use
105+
- Instead of CI3's ``$this->load->library('x');`` you can now use
106106
``$this->x = new X();``, following namespaced conventions for your component.
107107

108108
Helpers
109109
=======
110110

111-
- Helpers are pretty much the same as before, though some have been simplified.
111+
- :doc:`Helpers <../general/helpers>` are pretty much the same as before, though some have been simplified.
112+
- Some helpers from CodeIgniter 3 no longer exists in Version 4. For all these
113+
helpers, you have to find a new way to implement your functions. These
114+
helpers are `CAPTCHA Helper <https://www.codeigniter.com/userguide3/helpers/captcha_helper.html>`_,
115+
`Email Helper <https://www.codeigniter.com/userguide3/helpers/email_helper.html>`_.
116+
`Path Helper <https://www.codeigniter.com/userguide3/helpers/path_helper.html>`_.
117+
and `Smiley Helper <https://www.codeigniter.com/userguide3/helpers/smiley_helper.html>`_.
118+
- `Download Helper <https://www.codeigniter.com/userguide3/helpers/download_helper.html>`_
119+
in CI3 was removed. You need to use Response object where you are using ``force_download()``.
120+
See :ref:`force-file-download`.
121+
- `Language Helper <https://www.codeigniter.com/userguide3/helpers/language_helper.html>`_
122+
in CI3 was removed. But ``lang()`` is always available in CI4. See :php:func:`lang()`.
123+
- `Typography Helper <https://www.codeigniter.com/userguide3/helpers/typography_helper.html>`_
124+
in CI3 wll be :doc:`Typography Library <../libraries/typography>` in CI4.
125+
- `Directory Helper <https://www.codeigniter.com/userguide3/helpers/directory_helper.html>`_
126+
and `File Helper <https://www.codeigniter.com/userguide3/helpers/file_helper.html>`_ in CI3
127+
will be :doc:`../helpers/filesystem_helper` in CI4.
128+
- `String Helper <https://www.codeigniter.com/userguide3/helpers/string_helper.html>`_ functions
129+
in CI3 are included in :doc:`../helpers/text_helper` in CI4.
112130
- In CI4, ``redirect()`` returns a ``RedirectResponse`` instance instead of redirecting and terminating script execution. You must return it.
113131
- `redirect() Documentation CodeIgniter 3.X <https://codeigniter.com/userguide3/helpers/url_helper.html#redirect>`_
114132
- `redirect() Documentation CodeIgniter 4.X <../general/common_functions.html#redirect>`_
115133

116134
Events
117135
======
118136

119-
- Hooks have been replaced by Events.
137+
- `Hooks <https://www.codeigniter.com/userguide3/general/hooks.html>`_ have been
138+
replaced by :doc:`../extending/events`.
120139
- Instead of CI3's ``$hook['post_controller_constructor']`` you now use
121140
``Events::on('post_controller_constructor', ['MyClass', 'MyFunction']);``, with the namespace ``CodeIgniter\Events\Events;``.
122141
- Events are always enabled, and are available globally.
@@ -126,17 +145,18 @@ Extending the Framework
126145

127146
- You don't need a **core** folder to hold ``MY_...`` framework
128147
component extensions or replacements.
129-
- You don't need ``MY_x`` classes inside your libraries folder
148+
- You don't need ``MY_X`` classes inside your libraries folder
130149
to extend or replace CI4 pieces.
131150
- Make any such classes where you like, and add appropriate
132151
service methods in **app/Config/Services.php** to load
133152
your components instead of the default ones.
153+
- See :doc:`../extending/core_classes` for details.
134154

135155
Upgrading Libraries
136156
*******************
137157

138158
- Your app classes can still go inside **app/Libraries**, but they don't have to.
139-
- Instead of CI3's ``$this->load->library(x);`` you can now use ``$this->x = new X();``,
159+
- Instead of CI3's ``$this->load->library('x');`` you can now use ``$this->x = new X();``,
140160
following namespaced conventions for your component.
141161
- Some libraries from CodeIgniter 3 no longer exists in Version 4. For all these
142162
libraries, you have to find a new way to implement your functions. These

user_guide_src/source/installation/upgrade_controllers.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ What has been changed
1515
=====================
1616

1717
- Since namespaces have been added to CodeIgniter 4, the controllers must be changed to support namespaces.
18-
- Controllers don't use constructors any more (to invoke CI 'magic') unless those are part of base controllers you make.
19-
- CI provides Request and Response objects for you to work with - more powerful than the CI3-way.
20-
- If you want a base controller (``MY_Controller`` in CI3), make it where you like,
21-
e.g., BaseController extends Controller, and then have your controllers extend it
18+
- The constructor of CI4 Controller does not automatically load core classes into the properties.
19+
- CI4's Controller has a special constructor :ref:`initController() <controller-constructor>`.
20+
- CI4 provides :doc:`Request </incoming/incomingrequest>` and :doc:`Responses </outgoing/response>`
21+
objects for you to work with - more powerful than the CI3-way.
22+
- If you want a base controller (``MY_Controller`` in CI3), use **app/Controllers/BaseController.php**.
2223

2324
Upgrade Guide
2425
=============

user_guide_src/source/installation/upgrade_controllers/ci3sample/001.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ class Helloworld extends CI_Controller
44
{
55
public function index($name)
66
{
7-
echo "Hello $name! ";
7+
echo 'Hello ' . html_escape($name) . '!';
88
}
99
}

user_guide_src/source/installation/upgrade_models.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Upgrade Guide
2424
2. Add this line just after the opening php tag: ``namespace App\Models;``.
2525
3. Below the ``namespace App\Models;`` line add this line: ``use CodeIgniter\Model;``.
2626
4. Replace ``extends CI_Model`` with ``extends Model``.
27-
5. Instead of CI3's ``$this->load->model(x);``, you would now use ``$this->x = new X();``, following namespaced conventions for your component. Alternatively, you can use the :php:func:`model()` function: ``$this->x = model('X');``.
27+
5. Instead of CI3's ``$this->load->model('x');``, you would now use ``$this->x = new X();``, following namespaced conventions for your component. Alternatively, you can use the :php:func:`model()` function: ``$this->x = model('X');``.
2828

2929
If you use sub-directories in your model structure you have to change the namespace according to that.
3030
Example: You have a version 3 model located in **application/models/users/user_contact.php** the namespace has to be ``namespace App\Models\Users;`` and the model path in the version 4 should look like this: **app/Models/Users/UserContact.php**
3131

3232
The new Model in CI4 has a lot of built-in methods. For example, the ``find($id)`` method. With this you can find data where the primary key is equal to ``$id``.
3333
Inserting data is also easier than before. In CI4 there is an ``insert($data)`` method. You can optionally make use of all those built-in methods and migrate your code to the new methods.
3434

35-
You can find more information to those methods :doc:`here </models/model>`.
35+
You can find more information to those methods in :doc:`../models/model`.
3636

3737
Code Example
3838
============

user_guide_src/source/installation/upgrade_views.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ What has been changed
1515
=====================
1616

1717
- Your views look much like before, but they are invoked differently ... instead of CI3's
18-
``$this->load->view(x);``, you can use ``return view(x);``.
19-
- CI4 supports *View Cells* to build your response in pieces, and *View Layouts* for page layout.
20-
- The template parser is still there, and substantially enhanced.
18+
``$this->load->view('x');``, you can use ``return view('x');``.
19+
- CI4 supports :doc:`../outgoing/view_cells` to build your response in pieces,
20+
and :doc:`../outgoing/view_layouts` for page layout.
21+
- The :doc:`Template Parser <../outgoing/view_parser>` is still there, and substantially enhanced.
2122

2223
Upgrade Guide
2324
=============

user_guide_src/source/installation/upgrade_views/ci3sample/001.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<html>
22
<head>
3-
<title><?php echo $title; ?></title>
3+
<title><?php echo html_escape($title); ?></title>
44
</head>
55
<body>
6-
<h1><?php echo $heading; ?></h1>
6+
<h1><?php echo html_escape($heading); ?></h1>
77

88
<h3>My Todo List</h3>
99

1010
<ul>
1111
<?php foreach ($todo_list as $item): ?>
12-
<li><?php echo $item; ?></li>
12+
<li><?php echo html_escape($item); ?></li>
1313
<?php endforeach; ?>
1414
</ul>
1515

user_guide_src/source/outgoing/response.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ parameter. This is not case-sensitive.
5959

6060
.. literalinclude:: response/006.php
6161

62+
.. _force-file-download:
63+
6264
Force File Download
6365
===================
6466

0 commit comments

Comments
 (0)