Display data from from model without any relation in yii2 -


i have 2 models 1. orders 2. offers. there's no relation between them. in view file of order want display of_name,of_desc latest entry of offer table. offer searchmodel looks like:

public function search($params)     {         $query = offers::find()->orderby(['of_id' => sort_desc])->one();;          // add conditions should apply here          $dataprovider = new activedataprovider([             'query' => $query,         ]);          $this->load($params);          if (!$this->validate()) {             // uncomment following line if not want return records when validation fails             // $query->where('0=1');             return $dataprovider;         }          // grid filtering conditions         $query->andfilterwhere([             'of_id' => $this->of_id,         ]);          $query->andfilterwhere(['like', 'of_name', $this->of_name])             ->andfilterwhere(['like', 'of_description', $this->of_description]);          return $dataprovider;     } 

in controller action of order i've tried -

public function actionprintorders($id) {          $model = $this->findmodel($id);         $searchmodel  = new orderssearch();         $dataprovider = $searchmodel->search(yii::$app->request->queryparams);         $data         = orders::findone($id);          $searchmodel1 = new offerssearch();         //$dataprovider1 = $searchmodel1->search(yii::$app->request->queryparams);         $content = $this->renderpartial('_printorder', [             'model' => $model,             'dataprovider' => $dataprovider,             'searchmodel'  => $searchmodel,             'data'=> $data,             'searchmodel1' => $searchmodel1,             //'dataprovider1' => $dataprovider1,             //'model2' => $model2,             //'period' => $period,              ]);         $footer = "<table name='footer' width=\"1000\">            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>working hours : </u></td>            </tr>            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am 9:00pm</td>            </tr>            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">friday morning closed</td>                           <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">prop:      m.sinha</td>            </tr>          </table>";         $pdf = new pdf([             'mode'=> pdf::mode_utf8,             'format'=> pdf::format_a4,             'destination'=> pdf::dest_browser,             //'destination' => pdf::dest_download,             'cssfile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',             // css embedded if required             'cssinline' => '.kv-heading-1{font-size:18px}',               // set mpdf properties on fly             'options' => ['title' => 'print orderslip'],             //'options' => ['defaultfooterline' => 0,],              // call mpdf methods on fly             'methods' => [                 'setheader'=>['amit optical'],                  'setfooter'=>[$footer],             ],             'content' => $content,          ]);         return $pdf->render();         //return $this->render('_printsalarystatement', ['s_period' => $s_period]);      } 

and tried pass value in order view -

<h3 style="margin-bottom:0;margin-top:2;margin-left:2;"><strong><p class="text-center"><?php echo $searchmodel1['of_name'];?></p></strong></h3> 

there's no error there's no output line either. please tell me how it.

update i've tried solution made here yii2 render 2 models in 1 view stuck @ $key. not sure how pass it. present controller action looks below.

public function actionprintorders($id) {          $model = $this->findmodel($id);         $searchmodel  = new orderssearch();         $dataprovider = $searchmodel->search(yii::$app->request->queryparams);         $data         = orders::findone($id);          $searchmodel1 = new offerssearch();         $modeloffer  = offers::findone($key);         //$dataprovider1 = $searchmodel1->search(yii::$app->request->queryparams);         $content = $this->renderpartial('_printorder', [             'model' => $model,             'dataprovider' => $dataprovider,             'searchmodel'  => $searchmodel,             'data'=> $data,             'searchmodel1' => $searchmodel1,             'modeloffer'=>$modeloffer,             //'dataprovider1' => $dataprovider1,             //'model2' => $model2,             //'period' => $period,              ]);         $footer = "<table name='footer' width=\"1000\">            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\"><u>working hours : </u></td>            </tr>            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">9:00am 9:00pm</td>            </tr>            <tr>              <td style='font-size: 18px; padding-bottom: 20px;' align=\"left\">friday morning closed</td>                           <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">prop:      m.sinha</td>            </tr>          </table>";         $pdf = new pdf([             'mode'=> pdf::mode_utf8,             'format'=> pdf::format_a4,             'destination'=> pdf::dest_browser,             //'destination' => pdf::dest_download,             'cssfile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',             // css embedded if required             'cssinline' => '.kv-heading-1{font-size:18px}',               // set mpdf properties on fly             'options' => ['title' => 'print orderslip'],             //'options' => ['defaultfooterline' => 0,],              // call mpdf methods on fly             'methods' => [                 'setheader'=>['amit optical'],                  'setfooter'=>[$footer],             ],             'content' => $content,          ]);         return $pdf->render();      } 

the error @ beginning of code, should be

public function search($params)     {         $query = offers::find()->orderby(['of_id' => sort_desc]); 

without ->one() @ end of $query var, because activedataprovider needs \yii\db\activequery object.


Comments