0
0

TestController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace console\controllers;
  8. use common\models\AdminLog;
  9. use common\models\Customer;
  10. use yii\console\Controller;
  11. use yii\data\ActiveDataProvider;
  12. /**
  13. * This command echoes the first argument that you have entered.
  14. *
  15. * This command is provided as an example for you to learn how to create console commands.
  16. *
  17. * @author Qiang Xue <qiang.xue@gmail.com>
  18. * @since 2.0
  19. */
  20. class TestController extends Controller
  21. {
  22. /**
  23. * This command echoes what you have entered as the message.
  24. * @param string $message the message to be echoed.
  25. */
  26. public function actionIndex($message = 'hello world')
  27. {
  28. $customer = Customer::find()->all();
  29. // var_dump($customer);
  30. $str = '';
  31. foreach($customer as $k => $v){
  32. $str .="BEGIN:VCARD
  33. VERSION:3.0
  34. PRODID:-//Apple Inc.//iOS 11.2.1//EN
  35. N:".$v->name.";;;;
  36. FN:".$v->name."
  37. item1.TEL;type=pref:".$v->tel."
  38. REV:2018-01-15T08:22:36Z
  39. END:VCARD
  40. \n";
  41. }
  42. $str = rtrim($str, ',');
  43. //打印输出
  44. $myfile = fopen("newfile.vcf", "w") or die("Unable to open file!");
  45. fwrite($myfile, $str);
  46. fwrite($myfile, $str);
  47. fclose($myfile);
  48. die;
  49. }
  50. public function actionCreate() {
  51. echo 'advanced';
  52. }
  53. }