PHP code example of ims / php-service

1. Go to this page and download the library: Download ims/php-service library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ims / php-service example snippets


use phpService\PdfService;

//实例化
$api = new  PdfService();

//生成pdf
$data = [];
$data['file_name'] = 'pdf';
$data['title_header'] = '页首';
$data['title_footer'] = '页尾';
$data['content'] = '<img src="file/demo.jpg" style="width: 1100px"/>';
$data['water_text'] = '水印';
$data['is_down'] = 0;
$api->strToPdf($data);
die;

        namespace app\index\model;
		
		use ImsCommonService\BaseModel;

		/**
		 * DemoModel demo 模型
		 * @version 1.0
		 * @author: W_wang
		 * @since: 2019/1/25 9:51
		 */
		class DemoModel extends BaseModel
		{

			public function __construct()
			{
				parent::__construct();
				//初始化表名称
				$this->table = env('DB_DATABASE') . '.wh_demo';
				// 排序字段
				$this->order = 'id desc';
				$this->fields = 'id,name,wh_demo.age';//初始化返回字段
				$this->isShowSql = 1;//初始化返回sql标识0不返回,1返回

				//链表配置(可选)
				$this->joinTable = 'wh_dept';
				$this->joinVal = 'wh_demo.demo_id = wh_dept.id';
				$this->joinType = 'left';
			}
		}
    

        namespace app\index\controller;
		
		use think\Controller;
		use ImsCommonService\TpCacheService;

		/**
		 * DemoController demo 控制器
		 * @version 1.0
		 * @author: W_wang
		 * @since: 2019/1/25 9:51
		 */
		class DemoController extends Controller
		{

			public function cache()
			{
				$this->cache = new TpCacheService();
				//缓存key
				$cacheKey = 'demo';
				//写缓存
				$re = $this->cache->set($cacheKey, time(), 100);
				var_dump($re);
				//读缓存
				$re = $this->cache->get($cacheKey);
				var_dump($re);
				//删除缓存
				// $re = $this->cache->delete($cacheKey);
				var_dump($re);

				缓存组用法
				//缓存组key
				$cacheKeyMain = 'demo_main';
				//写缓存(组)
				$re = $this->cache->saveWithKey($cacheKeyMain, $cacheKey . rand(1, 100), array(
					"do" => 1,
					"data" => time()
				), 100);
				var_dump($re);
				//删除缓存(组)
				// $re = $this->cache->delWithKey($cacheKeyMain);
				var_dump($re);
			}
		}