简体   繁体   English

扩展zend db select

[英]extending zend db select

I am building a CMS kind of site, There will be lot of admin users. 我正在建立一个CMS类型的网站,会有很多管理员用户。 ACL was in place for business layer. ACL已用于业务层。 But now we want to apply custom ACL logic to models based on city in which admin user belongs. 但现在我们要将自定义ACL逻辑应用于基于admin用户所属城市的模型。

For eg: Admin user is from New York. 例如:管理员用户来自纽约。 He can view the content related to New York City. 他可以查看与纽约市相关的内容。

I have lot of queries built with Zend_Db_Select in the models. 我在模型中使用Zend_Db_Select构建了很多查询。 Now I have change the queries everywhere. 现在我已经在各处更改了查询。 Is there a way, I can add the logic ->where('u.city_id = ?', $admin_user_city_id) for each and every query. 有没有办法,我可以为每个查询添加逻辑 - > where('u.city_id =?',$ admin_user_city_id)。

Thanks in advance. 提前致谢。

Thanks Venu 谢谢Venu

I think that you might not need to extend Zend_Db_Table_Select . 我认为您可能不需要扩展Zend_Db_Table_Select You can do what you're looking for by only extending Zend_Db_Table_Abstract with a My_Db_Table_Abstract that all your models will extend too. 您可以通过仅使用My_Db_Table_Abstract扩展Zend_Db_Table_Abstract来完成您正在寻找的My_Db_Table_Abstract ,您的所有模型也将扩展。 In that abstract class, you'll extend the default select() that returns a Zend_Db_Table_Select and, before returning it, you just add your where clause to it. 在该抽象类中,您将扩展返回Zend_Db_Table_Select的默认select() ,并在返回之前,只需将where子句添加到它。

Thus, everytime you'll call a select with $myModel -> select() it will already contain your where clause. 因此,每次使用$myModel -> select()调用select时,它都会包含where子句。

abstract class My_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
    public function select($withFromPart = self::SELECT_WITHOUT_FROM_PART)
    {
        $select = parent::select($withFromPart);
        # Retreive $admin_user_city_id
        $select -> where('u.city_id = ?', $admin_user_city_id);
        return $select;
    }
}

Of course that also implies that you have made the correct join to your u table somewhere depending on the model you're on. 当然,这也意味着你已经做出了正确的加入到你的u表将取决于你在模型上的某个地方。

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

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