I have created application with CodeIgniter. I have view in my application. After rendering that view, is it possible to update/change only certain parts of rendered view from codeigniter backend? I would prefer to change parts of the view by rising events using codeigniter Events class. Is this possible?
This my controller home.php
:
<?php namespace App\Controllers;
use CodeIgniter\Events\Events;
class Home extends BaseController
{
public function index()
{
echo view('test_events');
}
public function testEvent(){
Events::trigger('kukuni');
}
//--------------------------------------------------------------------
}
This is my test_events.php
file:
<?php
use CodeIgniter\Events\Events;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
</head>
<body>
<?php
Events::on('kukuni', function()
{
echo "jjjjjjjjjjjjjjjjjjjj" ;
});
?>
</body>
</html>
Let me clarify even more what i want to achieve: I have firm knowledge, how to make for example Ajax calls with JavaScript from client side to server and update Dom and JavaScript data according to returned data. But in this case the "initiator" of update is client. I want the initiator to be server, not the client: something happens on server side, like some event gets fired, the view should change accordingly.
In the example i provided, i tried to rise event kukuni
inside testEvent()
controller function and handle that event inside test_events.php
which should echo
some random string but browser page does not get updated with this random string. I also prefer not to use any sort of manual polling in regular intervals from client to server.
Is this kind functionality feasible with CodeIgniter? What am i missing and/or doing wrong?
Thank you