Based on the application "blog" from the demos folder, created the commands folder in protected, and there - the products_import.php file.

Here are its contents:

<?php class ProductsImportCommand extends CConsoleCommand { public function actionIndex() { try { $products = Yii::app()->db->createCommand() ->select('product.id, product.url, product.name, product.price, product.price_old, product_section.name, product_category.name, product_img.name') ->from('product') ->join('product_assignment, product_section, product_category, product_img', 'product.id=product_assignment.product_id AND product_section.id=product_assignment.section_id AND product_category.id=product_assignment.category_id') ->order('product_img.type desc') ->queryAll(); $output = fopen('product_import.csv', 'w', ','); fputcsv($output, array('product.id', 'product.url', 'product.name', 'product.price', 'product.price_old', 'product_section.name', 'product_category.name', 'product_img.name')); foreach($products as $product) { fputcsv($output, $product); } fclose($output); } catch (Exception $e) { $this->logger->error($e->getMessage()); } } } 

Then he tried to start yicc ProductsImport index, but nothing is created, in the console he writes that only 4 standard yiic commands are available. What could be the problem?

UPD: Now it works. But where in the code of the SQL query may be an error, tell me, please? If you comment it out - is created.

    2 answers 2

    If my memory does not change, then you need to set the path to the file with the command class in the config file.

     'commandMap' => [ 'customCommand' => [ 'class' => /*path*/, //params => value, ... ], 
    • Now my configuration file console.php contains: <? Php // This is the configuration for yiic console application. // Any writable CConsoleApplication properties can be configured here. return array ('basePath' => dirname ( FILE ) .DIRECTORY_SEPARATOR. '..', 'name' => 'My Console Application',); - Timur Musharapov
    • @TimurMusharapov, it will probably be clearer here. yiiframework.com/doc/api/1.1/… ... - DanielOlivo
    • Yes, thanks a lot! It works now. But where in the code of the SQL query may be an error, tell me please? If you comment it out - is created. - Timur Musharapov

    Your file should be named the same as the class inside it ProductsImportCommand.php

    • Thank you, right. It works now. But where in the code of the SQL query may be an error, tell me, please? If you comment it out - is created. - Timur Musharapov
    • This does not apply to the original question, select the correct answer and create a separate question. And so look for your errors in the logs, because they themselves wrote $this->logger->error($e->getMessage()); - Bookin