小编st.*_*imp的帖子

Yii2 - 获取所有独特模型属性值的最佳方法是什么?

我的模型FAQ有4个属性

* @property integer $id * @property string $chapter * @property string $question * @property string $answer

现在我的actionIndex函数看起来像

public function actionIndex()
{

    $faq = Faq::find()->all();

    $dataProvider = new ActiveDataProvider([
        'query' => Faq::find(),
    ]);

    return $this->render('index', [
        'dataProvider' => $dataProvider,
        'faq' => $faq
    ]);
}
Run Code Online (Sandbox Code Playgroud)

如何在Controller中使用Yii2或PHP获取$ chapter的唯一值数组?让我们说在sql看起来像

SELECT DISTINCT chapter FROM ' faq_table'

php sql arrays activerecord yii2

8
推荐指数
1
解决办法
9154
查看次数

标签 统计

activerecord ×1

arrays ×1

php ×1

sql ×1

yii2 ×1