We can create our own event and it handle on server. Framework makes it easy, browser request routes to application events. One easy way to handle an event on server show here. if any user defined event is call from client side. In Client side event is show in url --
index-show-2.html
index = controller
show = event
2 = event argument
So Everything is well manage. You can check name of event on server and execute specific PHP code block. So you can manage your complex web application is very easily. Don't put HTML code in application that is bad practice.
Basic App Example to handle page events:-
class index extends \Sphp\tools\BasicApp {
private $ChatData = null;
public function onstart() {
$this->ChatData = new ChatData();
}
// $evtp == event parameter, myevent1 == any event name you want to handle
public function page_event_msg($evtp) {
$this->ChatData->sendMsg($this->Client->session('sesID'), "Operator", $this->Client->session('chat')['aname'], $this->Client->request('txttype'));
$this->JSServer->addJSONJSBlock('clearMsg();');
}
public function page_event_close($evtp) {
$this->dbEngine->executeQueryQuick("Update chatcon SET astatus=0 WHERE akey='" . $this->Client->session('sesID') . "'");
$this->ChatData->sendMsg($this->Client->session('sesID'), "Operator", "User has Leaved the Room");
$this->Client->session('chat', '');
}
public function page_event_sync($evtp) {
$msgar = $this->ChatData->readMsg($this->Client->session('sesID'));
if (count($msgar) > 0) {
if ($this->Client->session('chat')['wait'] == 'yes') {
$this->Client->session('chat')['wait'] = 'no';
}
}
$this->JSServer->addJSONJSBlock("$('#txtmsg1').append('System: $msgn'); scrollbottom();");
if ($this->Client->session('chat')['wait'] == 'no') {
$msgn = "";
$this->JSServer->addJSONJSBlock(" $msgn scrollbottom(); $('#outmsgbox').css('display','block'); ");
$this->Client->session('chat')['wait'] = 'chat';
} else if ($this->Client->session('chat')['wait'] == 'chat') {
$msgn = "";
foreach ($msgar as $tx_key => $arr) {
foreach ($arr as $key => $row) {
$msgn .= "$('#txtmsg1').append('" . $row['sender_name'] . ": " . $row['msg'] . "'); ";
}
}
$this->JSServer->addJSONJSBlock(" $msgn scrollbottom();");
}
}
}