PHP code example of cakephp / event
1. Go to this page and download the library: Download cakephp/event library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cakephp / event example snippets
use Cake\Event\Event;
use Cake\Event\EventDispatcherTrait;
class Orders
{
use EventDispatcherTrait;
public function placeOrder($order)
{
$this->doStuff();
$event = new Event('Orders.afterPlace', $this, [
'order' => $order
]);
$this->getEventManager()->dispatch($event);
}
}
$orders = new Orders();
$orders->getEventManager()->on(function ($event) {
// Do something after the order was placed
...
}, 'Orders.afterPlace');
$orders->placeOrder($order);