2014-12-04 41 views
0

在Yii框架中, 我該如何禁用defaultScopeYii框架重置defaultScope

我試過resetScope(false)resetScope(true) 但無濟於事。

任何幫助將非常感激。

+0

如果無法避免使用該功能,只需設定一些範圍後 – tinybyte 2014-12-04 05:56:46

+0

@tinybyte您好我試過,還有,但不知何故總是獲取添加默認的範圍。 – user1244197 2014-12-04 06:09:59

+0

@tinybyte public function defaultScope(){ $ t = $ this-> getTableAlias(false,false); return ['condition'=>「'$ t'.'status' = 1」]; (){ } \t public function scopes(){ $ t = $ this-> getTableAlias(false,false); return [ 'displayOff'=> ['condition'=>「'$ t'.'status' = 2」], ]; } \t \t我正在使用它。 \t XXX :: model() - > resetScope(true) - > displayOff(); \t \t 但燒製的QUERY是 \t \t SELECT * FROM XXX其中XXX.status = 1和XXX.status = 2; – user1244197 2014-12-04 06:13:27

回答

0

您可以通過覆蓋defaultScope()方法並返回空數組來禁用defaultScode。

public function defaultScope() 
{ 
    return array(); 
} 
+0

我無法做到這一點..因爲那樣我就不得不更新代碼在很多地方..我希望它的defaultScope可用於所有查詢接受爲我重設範圍的人。 – user1244197 2014-12-04 07:16:24

+0

只是在一個超級班。 – turutosiya 2014-12-05 01:18:55

+0

答案是絕對正確的。 +1 – 2016-10-05 15:46:48