php – 使用Slim Framework具有相同匿名回调的多个路由
发布时间:2020-12-13 16:24:54 所属栏目:PHP教程 来源:网络整理
导读:如何定义使用相同匿名回调的多个路由? $app-get('/first_route',function(){ //Do stuff});$app-get('/second_route',function(){ //Do same stuff}); 我知道我可以使用一个可以工作的函数的引用,但是我更喜欢使用匿名函数来解决其他代码库的一个解决方案.
|
如何定义使用相同匿名回调的多个路由?
$app->get('/first_route',function()
{
//Do stuff
});
$app->get('/second_route',function()
{
//Do same stuff
});
我知道我可以使用一个可以工作的函数的引用,但是我更喜欢使用匿名函数来解决其他代码库的一个解决方案. 所以基本上,我正在寻找的是一种做这样的事情: $app->get(['/first_route','/second_route'],function()
{
//Do same stuff for both routes
});
?OR? $app->get('/first_route',function() use($app)
{
$app->get('/second_route');//Without redirect
});
谢谢.
您可以使用条件来实现.我们用它来翻译URL.
$app->get('/:route',function()
{
//Do same stuff for both routes
})->conditions(array("route" => "(first_route|second_route)"));
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |








