123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace Demo\Service;
- use Dever;
- class News
- {
- # 测试事务方式1:后缀为commit即可
- public function test_commit_api()
- {
- $cat = Dever::db('demo/cat');
- $data['name'] = '服饰' . time();
- $id[] = $cat->insert($data);
- $data['name'] = '潮流' . time();
- print_r($id);
- $data['id'] = 1;
- $id[] = $cat->insert($data);
- print_r($id);
- }
- # 测试事务方式2
- public function test_sw_api()
- {
- $cat = Dever::db('demo/cat');
- try {
- $cat->begin();
- $data['name'] = '服饰' . time();
- $id[] = $cat->insert($data);
- $data['name'] = '潮流' . time();
- $data['id'] = 1;
- $id[] = $cat->insert($data);
- $cat->commit();
- } catch (\Exception $e) {
- $cat->rollBack();
- }
- $data = $cat->getList();
- echo Dever::sql();
- return $data;
- }
- # 测试用dever::load直接调取url
- public function curl_api()
- {
- $data = Dever::load('http://www.vogue.com.cn/');
- print_r($data);die;
- }
- # 随便写一个数据
- public function data()
- {
- return array
- (
- 0 => array
- (
- 'id' => 1,
- 'name' => 't12',
- ),
- 1 => array
- (
- 'id' => 2,
- 'name' => 't22',
- )
- );
- }
- # api代理器,用于浏览器调用上述data
- # 访问方法:xx.demo.8dev.net/service/news.proxy?method=demo/service/news.data&test=1
- public function proxy_api()
- {
- $method = Dever::input('method');
- return Dever::load($method);
- }
- public function getData()
- {
- $config = array
- (
- 'id' => 1,
- 'type' => 3,
- 'data1' => array
- (
- 0 => array
- (
- 'id' => 1,
- 'name' => 't1',
- ),
- 1 => array
- (
- 'id' => 2,
- 'name' => 't2',
- )
- ),
- 'data2' => array
- (
- 0 => array
- (
- 'id' => 3,
- 'name' => 't3',
- ),
- 1 => array
- (
- 'id' => 4,
- 'name' => 't4',
- )
- ),
- );
- return $config;
- }
- public function get_api($callback)
- {
- //Dever::debug(11);
- return $callback;
- }
- public function get()
- {
- $param['option_title'] = array('邹游:最具学者胸怀和气质的设计师', 'like');
- $param['group'] = 'nid';
- $param['limit'] = '0,10';
- $data = Dever::db('demo/news')->all($param);
- return $data;
- }
- # 测试传统模板
- public function test_smarty_api()
- {
- $data['test'] = 1111111111111;
- $data['data'] = $this->test_foreach();
- //return $data;
- return Dever::render('smarty', $data);
- }
- public function test_foreach()
- {
- $config = array
- (
- array
- (
- 'id' => 1,
- 'name' => '1111',
- 'child' => array
- (
- array
- (
- 'id' => 3,
- 'name' => '3333',
- 'child' => array
- (
- array
- (
- 'id' => 9,
- 'name' => '9999',
- ),
- array
- (
- 'id' => 10,
- 'name' => '10101010',
- )
- ),
- ),
- array
- (
- 'id' => 4,
- 'name' => '4444',
- )
- ),
- ),
- array
- (
- 'id' => 2,
- 'name' => '2222',
- 'child' => array
- (
- array
- (
- 'id' => 5,
- 'name' => '5555',
- ),
- array
- (
- 'id' => 6,
- 'name' => '6666',
- )
- ),
- )
- );
- return $config;
- }
- }
|