We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Anonymous function in router

Is it possible to pass anonymous function to router? Something like this?

$router->add('/page', function() { echo ' this is my page'; });

?



98.9k

If you use a Micro MVC yes: https://docs.phalcon.io/en/latest/reference/micro.html

<?php

$app = new Phalcon\Mvc\Micro();

$app->get('/say/welcome/{name}', function ($name) {
    echo "<h1>Welcome $name!</h1>";
});

$app->handle();


4.5k

Thanks, I assume there is no other way if I'm not using micro mvc?