public function saveOrderFtp() { $host = Yii::$app->params['ftp']['host']; $name = Yii::$app->params['ftp']['name']; $pass = Yii::$app->params['ftp']['pass']; $ftp = new FtpClient(); $ftp->connect($host); $ftp->login($name, $pass); $dirExist = $ftp->isDir('orders'); if (!$dirExist) { $ftp->mkdir('orders'); } if (ftp_chdir($ftp->getConnection(), "orders")) { $order = $this; $orderXML = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"windows-1251\"?><order></order>"); $orderXML->addAttribute('order_id', $order->order_id); $orderXML->addAttribute('create_time', $order->getFormattedCreateTime()); $orderXML->addAttribute('name', $order->name); $orderXML->addAttribute('email', $order->email); $orderXML->addAttribute('phone', $order->phone); $orderXML->addAttribute('delivery', $order->delivery); $orderXML->addAttribute('address', $order->address); $orderXML->addAttribute('comment', $order->comment); $products = $order->products; $productsXML = $orderXML->addChild('products'); foreach ($products as $product) { $productXML = $productsXML->addChild('product'); $productXML->addAttribute('product_id', $product->product_id); $productXML->addAttribute('name', $product->name); $productXML->addAttribute('quantity', $product->quantity); $productXML->addAttribute('price', $product->price); $productXML->addAttribute('summa', $product->summa); } $xml = $orderXML->asXML(); $ftp->putFromString('order_' . $order->order_id . '.xml', $xml); } }