title: Yii2 - API Rest - ActiveDataProvider
body: <p>I am building a REST API using Yii2 Basic Template. I am getting an error:</p>
  
  <pre><code>exception 'yii\base\InvalidArgumentException' with message 'Response content must be a string or an object implementing __toString().' in /Users/aurasix/ASX-Startups/ASX-CMS/asx-api-yii/vendor/yiisoft/yii2/web/Response.php:1062
  
  Copy Stacktrace Search Stackoverflow Search Google Exception
  Invalid Argument – yii\base\InvalidArgumentException
  Response content must be a string or an object implementing __toString().
  </code></pre>
  
  <p>I am following the guide on yii2 website: <a href="https://www.yiiframework.com/doc/guide/2.0/en/rest-resources" rel="nofollow noreferrer">https://www.yiiframework.com/doc/guide/2.0/en/rest-resources</a></p>
  
  <p>Trying to use collections, in order to use pagination and ordering in the future, am I missing something?</p>
  
  <p>I understand that if I use ActiveController probably this will be easier but I want to understand the full process that is why I am using Controller. Also I want full control, I think ActiveController will publish all methods just by defining the model, right?</p>
  
  <p>My controller I am not extending it from ActiveController but from Controller</p>
  
  <pre><code>namespace app\modules\v1\controllers;
  
  use yii\web\Controller;
  use app\modules\v1\models\Blog;
  use yii\data\ActiveDataProvider;
  
  class BlogController extends Controller {
  
      public $serializer = [
          'class' =&gt; 'yii\rest\Serializer',
          'collectionEnvelope' =&gt; 'items',
      ];
  
      public function actionIndex() {
          return new ActiveDataProvider([
              'query' =&gt; Blog::find()
          ]);
      }
  
  }
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>namespace app\modules\v1\models;
  
  use yii\db\ActiveRecord;
  use yii\web\Linkable;
  
  class Blog extends ActiveRecord implements Linkable {
  
      public static function tableName() {
          return 'blog_post';
      }
  
      public function fields() {
          return [
              'id',
              'slug',
              'title',
              'full_content'
          ];
      }
  
      public function extraFields() {
          return [
              'publish_date',
              'short_content'
          ];
      }
  
      public function getLinks() {
          return [
  
          ];
      }
  
  }
  </code></pre>
  
  <p>In config.php</p>
  
  <pre><code>'response' =&gt; [
              'formatters' =&gt; [
                  \yii\web\Response::FORMAT_JSON =&gt; [
                      'class' =&gt; 'yii\web\JsonResponseFormatter',
                      'prettyPrint' =&gt; YII_DEBUG, // use "pretty" output in debug mode
                      'encodeOptions' =&gt; JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
                  ],
              ],
          ],
  'urlManager' =&gt; [
              'enablePrettyUrl' =&gt; false,
              'showScriptName' =&gt; false,
              'rules' =&gt; [
                  [
                      'class' =&gt; 'yii\rest\UrlRule',
                      'controller' =&gt; 'v1/blog',
                      'pluralize'=&gt;false
                  ]
              ],
          ]
  </code></pre>