CDoc.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class CDoc
  16. {
  17. # 3.通过数组生成html文档样式
  18. /*
  19. $array = [
  20. 'title' => '1111',
  21. 'description' => 'xxxxxxxxxxxx',
  22. 'content' => [
  23. ['aaa','bbbb'],
  24. ['aaaaa','bbbbbbbbb'],
  25. ],
  26. ];
  27. */
  28. public static function tableformat($array){
  29. $t_str = '';
  30. $content = $array['content'];
  31. $i = 0;
  32. if(is_array($content) && !empty($content)){
  33. foreach($content as $d){
  34. $i++;
  35. if($i == 1){
  36. $t_str .='<thead><tr>';
  37. if(is_array($d) && !empty($d)){
  38. foreach($d as $v){
  39. $t_str .='<th>'.$v.'</th>';
  40. }
  41. }
  42. $t_str .='</tr></thead>';
  43. }else{
  44. if($i == 2)
  45. $t_str .='<tbody>';
  46. $t_str .='<tr>';
  47. if(is_array($d) && !empty($d)){
  48. foreach($d as $v){
  49. $t_str .='<td>'.$v.'</td>';
  50. }
  51. }
  52. $t_str .='</tr>';
  53. }
  54. }
  55. $t_str .='</tbody>';
  56. }
  57. $str = '
  58. <style>
  59. table.list th:first-child{
  60. width:22%;
  61. }
  62. </style>
  63. <table class="list" style="width:100%">
  64. <thead>
  65. <tr>
  66. <th>'.$array['title'].'</th>
  67. </tr>
  68. </thead>
  69. <tbody>
  70. <tr>
  71. <td>
  72. '.$array['description'].'
  73. <br/>
  74. <table class="list" style="width:100%">
  75. '.$t_str.'
  76. </table>
  77. </td>
  78. </tr>
  79. </tbody>
  80. </table>
  81. <br/>';
  82. return $str;
  83. }
  84. }