yii2-message icon indicating copy to clipboard operation
yii2-message copied to clipboard

memory is exhausted when compose a message

Open Gustik opened this issue 6 years ago • 1 comments

action message/message/compose show this error Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)

40K users

Gustik avatar May 21 '18 12:05 Gustik

Add action in MessageController

public function actionRecipients($q = null, $id = null)
    {
        \Yii::$app->response->format = Response::FORMAT_JSON;
        $out = ['results' => ['id' => '', 'username' => '']];
        if (!is_null($q)) {
            $data = User::find()->andFilterWhere(['like', 'username', $q])
                ->orderBy(['username' => SORT_DESC])->all();

            $out['results'] = array_values($data);
        } elseif ($id > 0) {
            $out['results'] = ['id' => $id, 'username' => User::findOne($id)->username];
        }
        return $out;
    }

and select users widget look like this

echo $form->field($model, 'to')->widget(Select2::className(), [
                'pluginOptions' => [
                    'allowClear' => true,
                    'minimumInputLength' => 3,
                    'ajax' => [
                        'url' => \yii\helpers\Url::to(['/message/message/recipients']),
                        'dataType' => 'json',
                        'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                        'processResults' => new JsExpression('
                                function (data, params) {
                                    return {
                                        results: $.map(data["results"], function (item) {
                                            return {
                                                id: item.id,
                                                text: item.username,
                                            };
                                        }),
                                        pagination: false,
                                    };
                                }
                            '),
                    ],
                    'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                    'templateResult' => new JsExpression('function(user) { return user.text; }'),
                    'templateSelection' => new JsExpression('function (user) { return user.text; }'),
                ],
                'showToggleAll' => false, # avoid accidental or malicious spam
                'options' => [
                    'multiple' => $allow_multiple,
                    'placeholder' => Yii::t('message', $allow_multiple ? 'Choose one or more recipients' : 'Choose the recipient'),
                ],
                'language' => Yii::$app->language ? Yii::$app->language : null,
            ]); ?>

Gustik avatar May 21 '18 12:05 Gustik