title: Trying to get property of non-object in action column in yii2
body: <p>I've customized the query in FrameSearch Model and build my query with findbysql. I'm also trying to customize the action column. My gridview looks fine except the action Column.
  Getting error - 
  <a href="https://i.stack.imgur.com/tSbKH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tSbKH.jpg" alt="enter image description here"></a></p>
  
  <p>FrameSearch Model Code - </p>
  
  <pre><code>&lt;?php
  
  namespace frontend\modules\framestock\models;
  
  use Yii;
  use yii\base\Model;
  use yii\data\ActiveDataProvider;
  use frontend\modules\framestock\models\Frame;
  use frontend\modules\framestock\models\Poitemframe;
  use yii\db\Query;
  use yii\db\Command;
  /**
   * FrameSearch represents the model behind the search form about `frontend\modules\framestock\models\Frame`.
   */
  class FrameSearch extends Frame
  {
      public $purchase;
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['f_id'], 'integer'],
              [['f_brand', 'f_name','purchase'], 'safe'],
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function scenarios()
      {
          // bypass scenarios() implementation in the parent class
          return Model::scenarios();
      }
  
      /**
       * Creates data provider instance with search query applied
       *
       * @param array $params
       *
       * @return ActiveDataProvider
       */
      public function search($params)
      {
          $subQuery1 = (new Query())-&gt;select(['poi_framename','sum(poi_qty) as purchased'])-&gt;from ('poitemframe')-&gt;join('LEFT JOIN','Frame','frame.f_name = poitemframe.poi_framename')-&gt;groupby('poi_framename');        
          $subQuery2 = (new Query())-&gt;select(['o_frame','count(o_frame) as sold'])-&gt;from ('orders')-&gt;join('LEFT JOIN','Frame','frame.f_name = orders.o_frame')-&gt;groupby('o_frame');        
          $query = (new Query())-&gt;select(['f_brand','f_name','COALESCE(pt.purchased,0)as purchased' , 'COALESCE(st.sold,0) as sold', '(COALESCE(pt.purchased,0) - COALESCE(st.sold,0)) as stock'])-&gt;from ('frame')-&gt;leftJoin(['pt' =&gt; $subQuery1],'pt.poi_framename = frame.f_name')-&gt;leftJoin(['st' =&gt; $subQuery2],'st.o_frame = frame.f_name');
  
  
          // -&gt;joinWith(['purchase']);
          // $items = $query
          //         -&gt;select([
          //             'f_brand',
          //             'f_name',
          //             'sum(poitemframe.poi_qty) as purchased',
          //             ])
          //         //-&gt;where(['stock.product_id'=&gt;3])
          //         -&gt;groupBy('f_name')
          //         -&gt;all();
  
  
  
          // add conditions that should always apply here
  
          $dataProvider = new ActiveDataProvider([
              'query' =&gt; $query,
          ]);
  
          $this-&gt;load($params);
  
          if (!$this-&gt;validate()) {
              // uncomment the following line if you do not want to return any records when validation fails
              // $query-&gt;where('0=1');
              return $dataProvider;
          }
  
          // grid filtering conditions
          $query-&gt;andFilterWhere([
              'f_id' =&gt; $this-&gt;f_id,
          ]);
  
          $query-&gt;andFilterWhere(['like', 'f_brand', $this-&gt;f_brand])
              -&gt;andFilterWhere(['like', 'f_name', $this-&gt;f_name]);
  
          return $dataProvider;
      }
  }
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\grid\GridView;
  use yii\db\Query;
  use yii\db\Command;
  
  /* @var $this yii\web\View */
  /* @var $searchModel frontend\modules\framestock\models\FrameSearch */
  /* @var $dataProvider yii\data\ActiveDataProvider */
  
  $this-&gt;title = 'Frames';
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  ?&gt;
  &lt;div class="frame-index"&gt;
  
      &lt;h1&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
      &lt;?php // echo $this-&gt;render('_search', ['model' =&gt; $searchModel]); ?&gt;
  
      &lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          'filterModel' =&gt; $searchModel,
          'columns' =&gt; [
              ['class' =&gt; 'yii\grid\SerialColumn'],
  
              'f_brand',
              'f_name',
              'purchased',
              'sold',
              'stock',
  
              [
              'class' =&gt; 'yii\grid\ActionColumn',
              'template' =&gt; '{ledger}',
              'buttons' =&gt; [
                  'ledger' =&gt; function ($url, $model) {
                      return Html::a(
                          '&lt;span class="glyphicon glyphicon-eye-open"&gt;&lt;/span&gt;',
                          ['/frame/ledger', 'f_name' =&gt; $model-&gt;f_name], 
                          [
                              'title' =&gt; 'Ledger',
                              'data-pjax' =&gt; '0',
                          ]
                      );
                  },
              ],
              ],
          ],
      ]); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>update</strong></p>
  
  <p><a href="https://i.stack.imgur.com/hJeJY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hJeJY.jpg" alt="enter image description here"></a></p>
  
  <p>After adding exit;
  <a href="https://i.stack.imgur.com/MkfAG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MkfAG.jpg" alt="enter image description here"></a></p>
  
  <p>Please tell me how to resolve this. I want to get the f_name from the action column button which I'll pass to another page to filter a grid.</p>