Merge pull request #5790 from kenjis/fix-docs-events

docs: fix events.rst
This commit is contained in:
kenjis 2022-03-15 09:40:08 +09:00 committed by GitHub
commit d95e46101d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -4,9 +4,9 @@ Replacing Common Functions
There are quite a few functions necessary to CodeIgniter that need to be loaded early for use in the core classes and
thus cannot be placed into a helper. While most users will never have any need to do this, but the option to replace
these functions does exist for those who would like to significantly alter the CodeIgniter core. In the ``App\``
directory there is a file ``Common.php``, and any functions defined in there will take precedence over the versions
found in ``system/Common.php``. This is also an opportunity to create globally-available functions you intend to
these functions does exist for those who would like to significantly alter the CodeIgniter core. In the **app/**
directory there is a file **Common.php**, and any functions defined in there will take precedence over the versions
found in **system/Common.php**. This is also an opportunity to create globally-available functions you intend to
use throughout the framework.
.. note:: Messing with a core system class has a lot of implications, so make sure you know what you are doing before

View File

@ -24,13 +24,13 @@ Defining an Event
=================
Most events are defined within the **app/Config/Events.php** file. You can subscribe an action to an event with
the Events class' ``on()`` method. The first parameter is the name of the event to subscribe to. The second parameter is
the ``Events`` class' ``on()`` method. The first parameter is the name of the event to subscribe to. The second parameter is
a callable that will be run when that event is triggered:
.. literalinclude:: events/001.php
In this example, whenever the **pre_controller** event is executed, an instance of ``MyClass`` is created and the
``MyFunction`` method is run. Note that the second parameter can be *any* form of
In this example, whenever the ``pre_system`` event is executed, an instance of ``MyClass`` is created and the
``myFunction()`` method is run. Note that the second parameter can be *any* form of
`callable <https://www.php.net/manual/en/function.is-callable.php>`_ that PHP recognizes:
.. literalinclude:: events/002.php

View File

@ -2,4 +2,4 @@
use CodeIgniter\Events\Events;
Events::on('pre_system', ['MyClass', 'MyFunction']);
Events::on('pre_system', ['MyClass', 'myFunction']);

View File

@ -5,7 +5,7 @@ Events::on('pre_system', 'some_function');
// Call on an instance method
$user = new User();
Events::on('pre_system', [$user, 'some_method']);
Events::on('pre_system', [$user, 'someMethod']);
// Call on a static method
Events::on('pre_system', 'SomeClass::someMethod');