Skip to content

Commit 52c4464

Browse files
authored
Merge pull request #7203 from kenjis/docs-add-factory-in-upgrade_4xx.rst
docs: add about Factories in upgrade_4xx
2 parents ccab9b7 + 31b8b63 commit 52c4464

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

user_guide_src/source/installation/upgrade_4xx.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,17 @@ Class Loading
100100
namespaces; with Composer autoloading support.
101101
- You can configure the class loading to support whatever application structure
102102
you are most comfortable with, including the "HMVC" style.
103+
- CI4 provides :doc:`../concepts/factories` that can load a class and share the
104+
instance like ``$this->load`` in CI3.
103105

104106
Libraries
105107
=========
106108

107109
- Your app classes can still go inside **app/Libraries**, but they don't have to.
108110
- Instead of CI3's ``$this->load->library('x');`` you can now use
109-
``$this->x = new X();``, following namespaced conventions for your component.
111+
``$this->x = new \App\Libraries\X();``, following namespaced conventions for
112+
your component. Alternatively, you can use :doc:`../concepts/factories`:
113+
``$this->x = \CodeIgniter\Config\Factories::libraries('X');``.
110114

111115
Helpers
112116
=======
@@ -162,8 +166,10 @@ Upgrading Libraries
162166
*******************
163167

164168
- Your app classes can still go inside **app/Libraries**, but they don't have to.
165-
- Instead of CI3's ``$this->load->library('x');`` you can now use ``$this->x = new X();``,
166-
following namespaced conventions for your component.
169+
- Instead of CI3's ``$this->load->library('x');`` you can now use
170+
``$this->x = new \App\Libraries\X();``, following namespaced conventions for
171+
your component. Alternatively, you can use :doc:`../concepts/factories`:
172+
``$this->x = \CodeIgniter\Config\Factories::libraries('X');``.
167173
- Some libraries from CodeIgniter 3 no longer exists in Version 4. For all these
168174
libraries, you have to find a new way to implement your functions. These
169175
libraries are `Calendaring <http://codeigniter.com/userguide3/libraries/calendar.html>`_,

0 commit comments

Comments
 (0)