Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions user_guide_src/source/extending/core_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the core versions.
**Most users will never have any need to do this, but the option to replace or extend them does exist for those
who would like to significantly alter the CodeIgniter core.**

.. note:: Messing with a core system class has a lot of implications, so make sure you know what you are doing before
.. important:: Messing with a core system class has a lot of implications, so make sure you know what you are doing before
attempting it.

.. contents::
Expand Down Expand Up @@ -47,15 +47,23 @@ The following is a list of the core system classes that are invoked every time C
Replacing Core Classes
======================

To use one of your own system classes instead of a default one, ensure that the :doc:`Autoloader <../concepts/autoloader>`
can find your class, that your new class implements the appropriate interface, and modify the appropriate
:doc:`Service <../concepts/services>` to load your class in place of the core class.
To use one of your own system classes instead of a default one, ensure:

1. the :doc:`Autoloader <../concepts/autoloader>` can find your class,
2. your new class implements the appropriate interface,
3. and modify the appropriate :doc:`Service <../concepts/services>` to load your class in place of the core class.

Creating Your Class
-------------------

For example, if you have a new ``App\Libraries\RouteCollection`` class that you would like to use in place of
the core system class, you would create your class like this:

.. literalinclude:: core_classes/001.php

Adding the Service
------------------

Then you would add the ``routes`` service in **app/Config/Services.php** to load your class instead:

.. literalinclude:: core_classes/002.php
Expand All @@ -65,7 +73,7 @@ Extending Core Classes

If all you need to is add some functionality to an existing library - perhaps add a method or two - then it's overkill
to recreate the entire library. In this case, it's better to simply extend the class. Extending the class is nearly
identical to replacing a class with one exception:
identical to `Replacing Core Classes`_ with one exception:

* The class declaration must extend the parent class.

Expand Down