Yii2 : Get Sum In footer of gridview
<p>I'm new here that I can't comment <a href="https://stackoverflow.com/questions/26852453/yii2-getting-sum-of-a-column">here</a> </p>

<p>and I have a problem when I try to Get sum in the footer . </p>

<p>my code in controller :</p>

<pre><code>$searchModel = new ReceiptsSearch();
$sum = new ReceiptsSearch();
$dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
 return $this-&gt;render('index', [
   'searchModel' =&gt; $searchModel,
   'dataProvider' =&gt; $dataProvider,
   'sum'=&gt;$sum,
   ]);
</code></pre>

<p>my SearchModel Code  : </p>

<pre><code>public function search($params)
{
    $query = Receipts::find();
    $sum = $query-&gt;sum('price');
    $dataProvider = new ActiveDataProvider([
        'query' =&gt; $query,
    ]);

    $this-&gt;load($params);

    if (!$this-&gt;validate()) {
        return $dataProvider;
    }
    $query-&gt;joinWith('patient'); 
    $query-&gt;andFilterWhere([
       'id' =&gt; $this-&gt;id,
       'price' =&gt; $this-&gt;price,
       'reg_date' =&gt; $this-&gt;reg_date,
    ]);
    $query-&gt;andFilterWhere(['like','patient.patient_name',$this-&gt;patient_id]);

    return $dataProvider;$sum;
}
</code></pre>

<p>my view page </p>

<pre><code>&lt;?= GridView::widget([

    'dataProvider' =&gt; $dataProvider,$sum,

    'filterModel' =&gt; $searchModel,
    'showFooter' =&gt; true,
    'columns' =&gt; [

        ['class' =&gt; 'yii\grid\SerialColumn'],

        [
        'attribute'=&gt;'patient_id',
        'value'=&gt;'patient.patient_name'
        ],
        'price',
        ],
        [
        'attribute' =&gt; 'sum',
        'footer' =&gt; 'sum',
        ],
        ['class' =&gt; 'yii\grid\ActionColumn'],
    ],
    ]); 
?&gt;
</code></pre>

<p>the message shown is : </p>

<blockquote>
  <p>Setting unknown property: yii\grid\GridView::0</p>
</blockquote>