'Yii2 filter data in controller

I'm new to YII framework, I want to filter my data on the frontend using product, month and year dropdown. Here is what I have in my controller

<?php
public function actionProducts()
    {
        $sql = "SELECT product, cost, supplier, month, year 
                FROM products
                WHERE year = :year
                GROUP BY product, month, year";
        $product = Data::findBySql($sql, [':year' => 2022])->asArray()->all();

        $response = ['data' => $product];
        header('Content-Type: application/json');
        return json_encode($response, JSON_NUMERIC_CHECK);
?>

How do I approach this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source