extending zend db select
I am building a CMS kind of site, There will be lot of admin users. ACL was in place for business layer. But now we want to apply custom ACL logic to models based on city in which admin user belongs.
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. Now I have change the queries everywhere. Is there a way, I can add the logic ->where('u.city_id = ?', $admin_user_city_id) fo开发者_如何学Gor each and every query.
Thanks in advance.
Thanks Venu
I think that you might not need to extend 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. 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.
Thus, everytime you'll call a select with $myModel -> select()
it will already contain your where clause.
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.
精彩评论