2013-10-18 25 views
0

在路由过滤器的IM试图确定路线参数被调用时,它可能为空,但我仍然需要知道,如果它被称为...检查是否路由参数被称为

例如

if(// IS ROUTE "job" being called ?) { 

    if(is_null($job = $route->getParameter('job'))) { 

     return App::abort(404, 'This job does not exist.'); // Show the not found page 
    } 
    elseif($job->agency->id != $agency->id) { 

     return App::abort(403, 'You are not authorized to view this job.'); // Show the insufficient permissions page 
    } 
} 
+0

你的意思是用文字“路径参数”?该网址参数是? – Andreyco

+0

路由参数与正在应用于该路由的变量... AKA Route :: post('{agency}/job/view/{job}','Controllers \ Agency \ JobController @ postEdit “); – AndrewMcLagan

回答

0

所以,我解决我自己的问题,林不知道,如果它的传统的或优雅的方式:

in_array('job', $route->getParameterKeys()) 

此检查,如果路线参数“工作”,被称为当前路线。很有用。

我以前的代码现在看起来像:

if(in_array('job', $route->getParameterKeys())) { 

    if(is_null($job = $route->getParameter('job'))) { 

     return App::abort(404, 'This job does not exist.'); // Show the not found page 
    } 
    elseif($job->agency->id != $agency->id) { 

     return App::abort(403, 'You are not authorized to view this job.'); // Show the insufficient permissions page 
    } 
}