2

I have got this error while using the code below in DetailView of Yii 2.

Object of class Closure could not be converted to string

The code is:

[
    'format' => 'raw',
    'attribute' => 'title',
    'value' => function($model1, $key) {
        if ($model1->book->language == 1) {
            $m = "<p class='n'>" . $model1->book->title . "</p>";
        } else {
            $m = $model1->book->title;
        }
        return $m;
    },
    'contentOptions' => ['class' => 'text-center'],
    'headerOptions' => ['class' => 'text-center']
],

Can you guys help me?

1 Answer 1

3

DetailView does not take closure like GridView for value, just string. Change it to:

'value' => $model1->book->language == 1 
           ? "<p class='n'>" . $model1->book->title . "</p>" 
           : $model1->book->title,
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.