<?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ namespace console\controllers; use common\models\AdminLog; use common\models\Customer; use yii\console\Controller; use yii\data\ActiveDataProvider; /** * This command echoes the first argument that you have entered. * * This command is provided as an example for you to learn how to create console commands. * * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */ class TestController extends Controller { /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex($message = 'hello world') { $customer = Customer::find()->all(); // var_dump($customer); $str = ''; foreach($customer as $k => $v){ $str .="BEGIN:VCARD VERSION:3.0 PRODID:-//Apple Inc.//iOS 11.2.1//EN N:".$v->name.";;;; FN:".$v->name." item1.TEL;type=pref:".$v->tel." REV:2018-01-15T08:22:36Z END:VCARD \n"; } $str = rtrim($str, ','); //打印输出 $myfile = fopen("newfile.vcf", "w") or die("Unable to open file!"); fwrite($myfile, $str); fwrite($myfile, $str); fclose($myfile); die; } public function actionCreate() { echo 'advanced'; } }