-
class
atk4\\ui\
Console
¶
Console¶
With console you can output real-time information about the process. We have put a lot of time to capture the output that may be generated by various means and stream it in real-time into HTML component.
Console uses Server Sent Event (jsSSE) which works pretty much out-of-the-box with the modern browsers and unlike websockets do not require you to set up additional ports on the server.
Demo: http://ui.agiletoolkit.org/demos/console.php
Basic Usage¶
-
atk4\\ui\Console::
set
($callback)¶
-
send($callback);
After adding a console to your Render Tree, you just need to set a call-back:
$console = $app->add('Console');
$console->set(function($console) {
// This will be executed through SSE request
$console->output('hello');
echo 'world'; // also will be redirected to console
sleep(2);
$console->send(new \atk4\ui\jsExpression('alert([])', ['The wait is over']);
});
Console integrates nicely with DebugTrait (http://agile-core.readthedocs.io/en/develop/debug.html?highlight=debug), and also allows you to execute shell process on the server while redirecting output in real-time.
Using With Model¶
We recommend that you pack up your busineess logic into your Model methods. When it’s time to call your method, you could either do this:
$user->generateReport(30);
Which would execute your own routine for some report generation, but doing it though a normal request will look like your site is slow and is unable to load page quick. Alternative is to run it through a console:
$console->setModel($user, 'generateReport', [30]);
This will display console to the user and will even output information from inside the model:
$this->info('converting report to PDF');