其余的ActiveDataProvider和关系数据/自定义字段

时间:2018-08-14 14:23:25

标签: yii2

我有一个rest控制器,它将返回应用程序内通知。通知模型仅保留有关通知类型和激活用户的参考ID,因为它们需要进行格式化才能显示。

我可以通过覆盖Highcharts.stockChart('container', { exporting: { buttons: { customButton: { text: 'Linear', onclick: function() { this.yAxis[0].update({ type: 'linear' }); } }, customButton2: { text: 'Logarithmic', onclick: function() { this.yAxis[0].update({ type: 'logarithmic' }); } }, customButton3: { text: 'Zoom', onclick: function() { $('#container').toggleClass('modal'); this.reflow(); } } } }, rangeSelector: { inputPosition: { align: 'left' } }, series: [{ data: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] }] }); 并手动返回一个数组来做到这一点,但是随后我错过了actionIndex()yii\rest\Controller结合使用的本机休息分页。

这是我当前的功能:

yii\data\ActiveDataProvider

格式化程序是在通知模型中定义的:

use yii\rest\Controller;

class NotificationController extends Controller
{
    public function actionIndex()
    {
        return new ActiveDataProvider([
            'query' => Notification::find()->joinWith(['type'])
        ]);
    }
}

但是我不能在public function getString() { return \modules\notifications\channels\Application::formatMessage($this->type->content, $this->data); } 中使用asArray()返回关系字段,也不能返回诸如query之类的额外参数。我可以将extraFields用于关系数据,但也需要对其进行格式化。

如何在ActiveDataProvider中从string返回string

0 个答案:

没有答案
相关问题