使用这个解决方案,我怎样才能让我的$conditions
变量到我的活动查询中?
$conditions = 'main_category_id != :main_category_id', ['category_status' => 1, 'main_category_id' => 0, 'sub_category_id' => $id,'type'=> 4];
$result = Category::find()->where($conditions)->orderby('category_name ASC')->all();
在我的查询main_category_id != 0
中。任何其他有效的解决方案也可以
请注意,我需要$conditions
变量,因为它们会有所不同。这是我对 if 语句的查询:
public function get_subcategory_list($id="",$type="")
{
$conditions = ['category_status' => 1, 'main_category_id' => 0, 'main_category_id' => $id, 'type' => 2];
if($type == 2){
$conditions = ['category_status' => 1, 'main_category_id' => 0, 'sub_category_id' => $id, 'type' => 3];
}
if($type == 3){
$conditions = ['category_status' => 1, 'main_category_id' => 0, 'sub_category_id' => $id,'type'=> 4];
}
$result = Category::find()->where($conditions)->orderby('category_name ASC')->all();
return $result;
}
请注意,$conditions
在上述函数上工作正常,唯一的问题是这里main_category_id
不应该等于 0。