Using this solution, how can I get my $conditions
variable to my active query?
$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();
On my query main_category_id != 0
. Any other solution that works is also fine
Please note that I need $conditions
variable as they vary. Here is my query with if statements:
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;
}
Please note that $conditions
works fine on the above function the only problem is here main_category_id
should not be equal to 0.