我想用Cakephp查找执行一个简单的OR语句..无法设法使这个或条件工作得非常正确,这往往会执行语句的第一部分而不是OR ..任何人提供任何指针?
$hols = $this->find('all', array(
'conditions' => array(
'Holiday.leave_type <>' =>3,
'Holiday.user_id' => $userID,
'Holiday.start >=' => $firstDayThisMonth,
'Holiday.start <=' => $lastDayThisMonth
),
'OR' => array(
'Holiday.leave_type' =>3,
'Holiday.active' => 1,
'Holiday.user_id' => null,
'Holiday.start >=' => $firstDayThisMonth,
'Holiday.start <=' => $lastDayThisMonth
)
)
答案 0 :(得分:1)
class MyFragment extends Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
//show keyboard when any fragment of this class has been attached
showSoftwareKeyboard(true);
}
@Override
public void onDetach() {
super.onDetach();
//hide keyboard when any fragment of this class has been detached
showSoftwareKeyboard(false);
}
protected void showSoftwareKeyboard(boolean showKeyboard){
final Activity activity = getActivity();
final InputMethodManager inputManager = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), showKeyboard ? InputMethodManager.SHOW_FORCED : InputMethodManager.HIDE_NOT_ALWAYS);
}
}
运算符仅适用于子数组。因此,要表达规则OR
,您必须编写A OR B
你的where子句的条件是:
'conditions'=>array('OR'=>array(array(A),array(B)))
您可以将其简化为:
$hols = $this->find('all', array(
'conditions' => array(
'OR'=>array(
array(
'Holiday.leave_type <>' =>3,
'Holiday.user_id' => $userID,
'Holiday.start >=' => $firstDayThisMonth,
'Holiday.start <=' => $lastDayThisMonth
),
array(
'Holiday.leave_type' =>3,
'Holiday.active' => 1,
'Holiday.user_id' => null,
'Holiday.start >=' => $firstDayThisMonth,
'Holiday.start <=' => $lastDayThisMonth
)
)
)
)