PHP Classes

File: examples/case-studies/ui/ui_event_binding/ui_event_binding.php

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/case-studies/ui/ui_event_binding/ui_event_binding.php   Download  
File: examples/case-studies/ui/ui_event_binding/ui_event_binding.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change: Update of examples/case-studies/ui/ui_event_binding/ui_event_binding.php
Date: 8 months ago
Size: 1,378 bytes
 

Contents

Class file image Download
<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : support@ascoos.com
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @desc <English> Bind client-side UI events to server-side logic
 * @desc <Greek> ???????? ???????? ??? ?? UI (?.?. `onClick`), ?? ?????? ???? server.
 *
 * @since PHP 8.2.0
 */
declare(strict_types=1);


use
ASCOOS\OS\Kernel\Arrays\Events\TEventHandler;

global
$AOS_LOGS_PATH;

try {
   
// ???????????? ??? TEventHandler
   
$eventHandler = new TEventHandler([], [
       
'logs' => [
           
'useLogger' => true,
           
'dir' => $AOS_LOGS_PATH . '/tmp/logs/',
           
'file' => 'events.log'
       
]
    ]);

   
// ?????????? ????????? onClick ??? UI ????????
   
$eventHandler->register('ui', 'onClick', function ($params) {
        echo
"Button clicked with element ID: " . $params['elementId'] . "\n";
    });

   
// ???????????? ??? ????????? ?? ???????? ??? client
   
$eventHandler->trigger('ui', 'onClick', ['elementId' => 'submitButton']);

   
// ???????????? ?????
   
$eventHandler->Free($eventHandler);

} catch (
InvalidArgumentException $e) {
    echo
'??????: ' . $e->getMessage();
}