test.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * 后台自定义处理模板
  4. */
  5. $view
  6. # 定义全局变量
  7. ->set('l1', 'demo/service/news.getData')
  8. ->fetch('s1:#fetch:这是描述', 'demo/service/news.getData#id')
  9. # 上边这句话可以理解为定义一个公平的模板绑定函数,下边call是使用方法
  10. //->call('demo/manage/test:s1')
  11. # 测试if逻辑判断
  12. ->render('l1', array
  13. (
  14. '#test' => array
  15. (
  16. 'if($v.type == 1)' => array
  17. (
  18. 'li|$v.data1' => array
  19. (
  20. 'span' => array
  21. (
  22. 'html' => '$v1.id'
  23. ),
  24. 'a' => array
  25. (
  26. 'html' => '$v1.name'
  27. ),
  28. ),
  29. ),
  30. 'else' => array
  31. (
  32. 'li|$v.data2' => array
  33. (
  34. 'span' => array
  35. (
  36. 'html' => '$v1.id'
  37. ),
  38. 'a' => array
  39. (
  40. 'html' => '$v1.name'
  41. ),
  42. ),
  43. ),
  44. 'endif' => 1,
  45. 'if($v.id == 1)' => '$v.data4 = $v.data1',
  46. 'else|1' => '$v.data4 = $v.data2',
  47. 'endif|1' => 2,
  48. '#t15 li|$v.data4' => array
  49. (
  50. 'span' => array
  51. (
  52. 'html' => '$v1.id'
  53. ),
  54. ),
  55. 'test' => 1,
  56. 'a|1' => array
  57. (
  58. 'if($v.type == 1)' => '$v.type = 2',
  59. 'else' => '$v.type = 3',
  60. 'endif' => 1,
  61. 'html' => '$v.type',
  62. ),
  63. ),
  64. ))
  65. ->render('l1', array
  66. (
  67. '#test1' => array
  68. (
  69. 'if($v.type == 1)' => '$v.data3 = $v.data1',
  70. 'elseif($v.type == 2)' => '$v.data3 = $v.data2',
  71. 'else' => '$v.data3 = $v.data2',
  72. 'endif' => 2,
  73. '#t12 li|$v.data3' => array
  74. (
  75. 'span' => array
  76. (
  77. 'html' => '$v1.id'
  78. ),
  79. 'a' => array
  80. (
  81. 'html' => '$v1.name'
  82. ),
  83. ),
  84. 'test' => 1,
  85. 'a|1' => array
  86. (
  87. 'html' => '333',
  88. ),
  89. 'if($v.id == 1)' => '$v.data4 = $v.data1',
  90. 'else|1' => '$v.data4 = $v.data2',
  91. 'endif|1' => 2,
  92. '#t13 li|$v.data4' => array
  93. (
  94. 'span' => array
  95. (
  96. 'html' => '$v1.id'
  97. ),
  98. ),
  99. ),
  100. ))
  101. ->loop('#test2 li', 'demo/service/news.data', array
  102. (
  103. 'span' => array
  104. (
  105. 'if($v.id == 1)' => '$v.id = 3',
  106. 'else' => '$v.id = 4',
  107. 'endif' => 2,
  108. 'html' => '$v.id'
  109. ),
  110. 'a|0' => array
  111. (
  112. 'html' => '$v.name'
  113. ),
  114. ))
  115. ->display();