* @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'; } }