/** * Lists all Listofgoods models. * @return mixed */ public function actionIndex() { $searchModel = new ListofgoodsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function actionDbtofile() { $filename = 'OrdersFile/test.txt'; //модель и провайдер для передачи во view $orderSearch = new OrdersSearch(); $dpOrder = $orderSearch->search(Yii::$app->request->queryParams); //модель для работы с текущими заказами $orders = Orders::find()->where(['status' => 'Размещен'])->all(); $w = fopen($filename, 'w'); //открываем файл для записи foreach ($orders as $dt) { //echo $dt['order_id']; $sm = new ListofgoodsSearch(); $dp = $sm->search(Yii::$app->request->queryParams, $dt['order_id']); foreach ($dp->models as $mod) { $strtofile = ''; $strtofile .= $dt['order_id'] . ';'; $strtofile .= $dt['order_timestamp'] . ';'; $strtofile .= $dt['customersCustomer']['customer_name'] . ';'; $strtofile .= $mod['goodsGoodId']['good_name'] . ';'; $good_price = $mod['goodsGoodId']['good_price'] / 100; $strtofile .= $good_price . ';'; $strtofile .= $mod['good_count'] . ';'; $strtofile .= "\r\n"; fputs($w, $strtofile); //пишем в файл строку } $dt->status = 'Обработан'; $dt->save(); } fclose($w); //закрываем файл //$this->fileDownload(); return $this->render('index_adm', ['searchModel' => $orderSearch, 'dataProvider' => $dpOrder, 'getFile' => TRUE]); }
} else { return ['onclick' => 'window.location.href="' . Url::toRoute(['orders/view', 'id' => $model->order_id]) . '"; return false', 'style' => 'cursor:pointer']; } }, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'order_id', 'order_timestamp', ['attribute' => 'user_id', 'value' => 'usersUser.fullname'], ['attribute' => 'customers_customer_id', 'value' => 'customersCustomer.customer_name'], ['attribute' => 'order_amount', 'value' => function ($model) { return $model->order_amount / 100; }], 'status']]); ?> <?php Pjax::end(); ?> <?php //тут я тренируюсь выгружать данные в файл $order = new Orders(); $orders = $order->find()->where(['status' => 'Размещен'])->all(); foreach ($orders as $dt) { //print_r($dt); $sm = new ListofgoodsSearch(); $dp = $sm->search(Yii::$app->request->queryParams, $dt['order_id']); foreach ($dp->models as $mod) { echo ' ' . $dt['order_id']; echo ' ' . $dt['customersCustomer']['customer_name']; echo ' ' . $mod['goodsGoodId']['good_name']; $good_price = $mod['goodsGoodId']['good_price'] / 100; echo ' ' . $good_price; echo '<br>'; } } ?> </div>