limit(100)->all(); } public function createRow( $product, &$content ){ if ($this->checkId($product->product_id)) { print $product->product_id."\r\n"; //print $this->count++ . "\n"; $content[] = [$product->product_id, $product->name, $product->price]; } } public function checkId($id){ if(!in_array($id, $this->idList)){ $this->idList[] = $id; return true; } else { return false; } } public function actionProcess() { $dirName = Yii::getAlias('@frontend').'/web'; $filename = 'feed.csv'; setlocale(LC_ALL, 'ru_RU.CP1251'); $handle = fopen($dirName .'/'. $filename, "w"); $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; foreach ($this->getProducts() as $product) { $this->createRow($product, $content); } foreach ($content as $item) { fputcsv($handle, $item); } fclose($handle); print $dirName .'/'. $filename; } }