From 57afedf9bbf26107f55e254ddfc41de0691b507e Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 23 Jun 2022 21:15:24 +0900 Subject: [PATCH] docs: improve extending/core_classes.rst --- .../source/extending/core_classes.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/extending/core_classes.rst b/user_guide_src/source/extending/core_classes.rst index 8f923a2e14bd..efb42c53034e 100644 --- a/user_guide_src/source/extending/core_classes.rst +++ b/user_guide_src/source/extending/core_classes.rst @@ -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:: @@ -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 @@ -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.