Once events have been enabled in concrete5, developers can write their own code to respond to the different events. In this recipe, we will create a basic "Hello World!" event that runs immediately when a page is visited and outputs a message to the screen.
Before you can register an event in site_events.php
, concrete5 must be configured to enable the events system. Refer to the previous recipe to see how to enable events.
The steps are as follows:
Create a new file in
/config
calledsite_events.php
.Open
site_events.php
in your preferred code editor.Add the following code to listen to the
on_start
event.Events::extend('on_start', 'MyClass', 'onStartFired', 'libraries/my_class.php');
Create a new file in
/libraries
calledmy_class.php
.Define a new class called
MyClass
inmy_class.php
.class MyClass { }
Add a method to
MyClass
calledonStartFired
.public function onStartFired() { }
In
onStartFired
, use thedie
function to output hello world...