News.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace Demo\Vogue;
  3. use Dever;
  4. class News
  5. {
  6. # 测试事务方式1:后缀为commit即可
  7. public function test_commit_api()
  8. {
  9. $cat = Dever::db('demo/cat');
  10. $data['name'] = '服饰' . time();
  11. $id = $cat->insert($data);
  12. echo $id ."\r\n";
  13. $data = $cat->getList();
  14. //echo Dever::sql();
  15. print_r($data);
  16. $data['name'] = '潮流' . time();
  17. $data['id'] = 1;
  18. $id = $cat->insert($data);
  19. echo $id ."\r\n";
  20. $data = $cat->getList();
  21. //echo Dever::sql();
  22. print_r($data);
  23. return;
  24. }
  25. # 测试事务方式2
  26. public function test_shiwu_api()
  27. {
  28. $cat = Dever::db('demo/cat');
  29. try {
  30. $cat->begin();
  31. $data['name'] = '服饰' . time();
  32. $id = $cat->insert($data);
  33. echo $id ."\r\n";
  34. $data['name'] = '潮流' . time();
  35. $data['id'] = 1;
  36. $id = $cat->insert($data);
  37. echo $id ."\r\n";
  38. $cat->commit();
  39. } catch (\Exception $e) {
  40. $cat->rollBack();
  41. }
  42. $data = $cat->getList();
  43. echo Dever::sql();
  44. print_r($data);die;
  45. }
  46. public function curl_api()
  47. {
  48. //$data = Dever::load('http://www.vogue.com.cn/');
  49. //print_r($data);die;
  50. $data = Dever::load('cms/service/news.test_display_data');
  51. print_r($data);die;
  52. }
  53. public function data()
  54. {
  55. return array
  56. (
  57. 0 => array
  58. (
  59. 'id' => 1,
  60. 'name' => 't1',
  61. ),
  62. 1 => array
  63. (
  64. 'id' => 2,
  65. 'name' => 't2',
  66. )
  67. );
  68. }
  69. public function proxy_api()
  70. {
  71. $method = Dever::input('method');
  72. return Dever::load($method);
  73. }
  74. public function info()
  75. {
  76. return array
  77. (
  78. 'name' => 'bill',
  79. );
  80. }
  81. public function getData()
  82. {
  83. $config = array
  84. (
  85. 'id' => 1,
  86. 'type' => 3,
  87. 'data1' => array
  88. (
  89. 0 => array
  90. (
  91. 'id' => 1,
  92. 'name' => 't1',
  93. ),
  94. 1 => array
  95. (
  96. 'id' => 2,
  97. 'name' => 't2',
  98. )
  99. ),
  100. 'data2' => array
  101. (
  102. 0 => array
  103. (
  104. 'id' => 3,
  105. 'name' => 't3',
  106. ),
  107. 1 => array
  108. (
  109. 'id' => 4,
  110. 'name' => 't4',
  111. )
  112. ),
  113. );
  114. return $config;
  115. }
  116. public function index($name, $id)
  117. {
  118. //Dever::cache('test', array('1111'));
  119. //return 222;
  120. return Dever::load('demo/vogue/cat.test');
  121. return Dever::db('demo/cat')->all();
  122. Dever::$global['test'] = 1;
  123. return Dever::load('demo/vogue/cat.data', 1, '23232');
  124. //$cat = Dever::load('demo/vogue/cat');
  125. $cat = new Cat();
  126. if ($id == 1) {
  127. Dever::alert('错误');
  128. }
  129. //Dever::out($cat->data());die;
  130. return $cat->data();
  131. return $name;
  132. }
  133. public function test_display_api()
  134. {
  135. $data['test'] = 1111111111111;
  136. $data['data'] = $this->test_foreach();
  137. //return $data;
  138. return Dever::render('index', $data);
  139. }
  140. public function test_display_data()
  141. {
  142. return 12323234;
  143. }
  144. public function test_foreach()
  145. {
  146. $config = array
  147. (
  148. array
  149. (
  150. 'id' => 1,
  151. 'name' => '1111',
  152. 'child' => array
  153. (
  154. array
  155. (
  156. 'id' => 3,
  157. 'name' => '3333',
  158. 'child' => array
  159. (
  160. array
  161. (
  162. 'id' => 9,
  163. 'name' => '9999',
  164. ),
  165. array
  166. (
  167. 'id' => 10,
  168. 'name' => '10101010',
  169. )
  170. ),
  171. ),
  172. array
  173. (
  174. 'id' => 4,
  175. 'name' => '4444',
  176. )
  177. ),
  178. ),
  179. array
  180. (
  181. 'id' => 2,
  182. 'name' => '2222',
  183. 'child' => array
  184. (
  185. array
  186. (
  187. 'id' => 5,
  188. 'name' => '5555',
  189. ),
  190. array
  191. (
  192. 'id' => 6,
  193. 'name' => '6666',
  194. )
  195. ),
  196. )
  197. );
  198. return $config;
  199. }
  200. }