我想开发一个基于Slim Framework和Doctrine 2的RESTful API。我有一个详细的权限管理。所以我的权限定义为:
role:admin|entity:person|column:name|write:1
我正在考虑将最有效的方法实施到Web服务中。
因此,我需要在构建查询时过滤计算的列子集。什么是最好的地方,仍然允许我使用所有默认方法,如findAll()等。我当然可以过滤我的字段,如下所示:
$all = Article::createQuery('a')->getArrayResult();
/*this is getting ALL the fields -it would be better to filter before
retrieving from the db
*/
$allFiltered = array();
foreach($all as $index=>$article){
$filteredArticle = new Article();
foreach($user->getPermission('Article','r') as $permission){
$column = $permission->column;
$filteredArticle->$column = $article->$column;
}
$allFiltered[$index]=$filteredArticle
)
$app->response->setBody(json_encode($all));
有没有办法在一个地方为所有检索方法执行此操作?