Hi again. According to that: https://olddocs.phalcon.io/en/3.0.0/reference/tutorial-invo-2.html and that: https://olddocs.phalcon.io/en/3.0.0/api/Phalcon_Mvc_Dispatcher.html I added to services.php:
$di->set(
"dispatcher",
function () {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach(
'dispatch:beforeExecuteRoute',
new SecurityService()
);
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}
);
And of course my implementation in service:
public function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Dispatcher $dispatcher)
{
$router = new \Phalcon\Mvc\Router();
$router->add('/index/test')->setName('test');
$router->handle();
if ($router->wasMatched()) {
//it performs well, according to my expectations
file_put_contents('test1.txt', 'Well done!');
}else{
//this is sth extraterrestrial !!!
file_put_contents('test2.txt', 'Phalcon secret parser here');
echo 'I am in (|)';
exit;
}
}
Of course I call /index/test action by URL (to ensure that effect occurs at least 5 times, sometimes works in first time, I don't know why)
Could someone tell me, why both files apear when I call /index/test? How can I code when basic control structures don't work?