Multiple routes with the same anonymous callback using Slim Framework

走远了吗. 提交于 2019-11-29 09:24:27

You can use conditions to achieve just that. We use that to translate URLs.

$app->get('/:route',function()
{
    //Do same stuff for both routes
})->conditions(array("route" => "(first_route|second_route)"));

I can't give you a framework specific solution, but if it helps you can reference anonymous function:

$app->get('/first_route', $ref = function()
{
   //Do stuff
});
$app->get('/second_route', $ref);

Callbacks are delegates. So you can do something like that :

$app->get('/first_route', myCallBack);
$app->get('/second_route', myCallBack);

function myCallBack() {
    //Do stuff
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!