CMS Events
The Events system in CMS Full Form allows you to execute custom actions when specific system events occur. This enables you to extend and customize the functionality of the CMS without modifying the core source code directly.
Events Directory Structure
application/
└── Events/
├── Backend/
│ ├── ExampleEvent.php
│ └── ...
└── Frontend/
├── ExampleEvent.php
└── ...
Backend/
: Contains events related to the admin panel or backend operations.Frontend/
: Contains events related to the public-facing side of the website.
Creating a New Event
Inside the appropriate folder (Backend
or Frontend
), create a new PHP file for your event, e.g., ExampleEvent.php
.
<?php
namespace App\Events\Frontend;
use System\Libraries\Event;
class ExampleEvent extends Event
{
public function __construct($data)
{
$this->data= $data;
}
public function handle()
{
// Perform an action when the event is triggered
echo "CMS Full Form Event: Data: " . json_encode($this->data) . "<br>";
}
}
$this->data
: Stores the data passed in when the event is triggered.handle()
: This method contains the logic that should run when the event is executed.
Using Event
<?php
namespace App\Controllers\Frontend;
use System\Core\BaseController;
class UsersController extends BaseController
{
public function index()
{
// Process data
........
//------------------------------ Call 1 event ------------------------------
// Setup data
$data = "Welcome to CMS Full Form Event";
// Call event
\System\Libraries\Events::run('Frontend\ExampleEvent', $data);
//--------------------------- Call Multiple event --------------------------
$events = [
'Frontend\ExampleEvent' => "Example Event",
'Frontend\AnotherEvent' => "Another Event",
];
\System\Libraries\Events::runs($events);
}
}
Note
Use clear event naming: Follow consistent naming conventions to make event management easier and more organized.
Handle exceptions within events: Ensure that exceptions are properly caught and handled inside the
handle()
method to avoid disrupting the main application flow.Optimize performance: If the event performs heavy tasks, consider using a queue system to handle the process asynchronously.
Last updated
Was this helpful?