如何防止所有detailView显示来自另一个用户的数据?
例如,当您在URL中键入另一个用户的产品ID时,就会发生这种情况。detailView正常显示产品的详细信息,但是属于另一个用户,甚至可以更改和删除它。
如果您不想使用RBAC,则可以在控制器中执行以下操作:
protected function findModel($id)
{
//Check if the author is the current user
if (($model = Product::findOne($id)) !== null && $model->author_id==Yii::$app->user->id) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
像这样的用户(非作者)无法查看,更新或删除产品。http://www.yiiframework.com/forum/index.php/topic/61915-prevent-show-data-from-another-user/page__view__findpost__p__274644
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句