简体   繁体   English

Zend Framework-阻止模型运行

[英]Zend Framework - Prevent a model from running

I want to be able to make a security check every time my models run. 我希望每次运行模型时都可以进行安全检查。 If the check fails, then I want to prevent the query to execute. 如果检查失败,那么我想阻止查询执行。 I have already created a MyWork_Model_Base that extends Zend_Db_Table_Abstract and my models then extend the MyWork_Model_Base. 我已经创建了扩展Zend_Db_Table_Abstract的MyWork_Model_Base,然后我的模型扩展了MyWork_Model_Base。 I think I should perform this check in the init(); 我认为我应该在init()中执行此检查; but I how do I prevent the model from running if it fails? 但是如果模型失败,我如何防止模型运行?

Thanks 谢谢

There is already class for such purposes - Zend_Acl 已经有用于此类目的的类-Zend_Acl

You can create resources (guest, authorized-users, admin), roles (guest, authorized-user, admin) and create "acl tables". 您可以创建资源(来宾,授权用户,管理员),角色(来宾,授权用户,管理员)并创建“ acl表”。

<?php
  $acl = new Zend_Acl();
?>

After creating all the necessery rules, you can check is user is allowed to run model with such code: 创建所有必需规则后,您可以检查是否允许用户使用以下代码运行模型:

<?php
   if ($acl->isAllowed('admin','admin-news','create')
?>

Which is checking is user with role 'admin' is allowed 'create' in resource 'admin-news'. 正在检查是否允许在资源“ admin-news”中“创建”具有角色“ admin”的用户。 As resource you can join module and controller and action would be last parameter. 作为资源,您可以加入模块和控制器,而动作将是最后一个参数。

Check should be provided in Controller_Plugin where you can change run action. 应该在Controller_Plugin中提供检查,您可以在其中更改运行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM