1.redis用法
redis
use Application\Service\DB\AbstractDb;
use Laminas\Db\TableGateway\TableGateway;
$redis = $this->LocalService('Redis');
$result = $redis ->setItem('test','string');
$result = $redis ->getItem('test');
给key值添加过期时间========
use Laminas\Cache\Storage\Adapter\Redis;=====过期必须引入
use Laminas\Db\ResultSet\ResultSet;
另一种连接redis
$redis = $this->LocalService('Redis');
过期时间添加
$redisOptionBack = $redis->getOptions()->setDatabase(8)->setNamespace( 'Redis' );//最外面的大key
$redis2 = new Redis( $redisOptionBack );
$redisOptionBack ->setTtl('43200');//过期时间12
$result = $redis2 ->setItem('cultivate:user:'.$cultivateUserFind['id'],$cultivateUserFindS);
2.sql添加事物
//事物
$adapter = $this->getEvent()->getApplication()->getServiceManager()->get("Zend\Db\Adapter\Adapter");
开启事物
$adapter ->getDriver()->getConnection()->beginTransaction();
事物回滚
$adapter ->getDriver()->getConnection()->rollback();
事物提交
$adapter ->getDriver()->getConnection()->commit();
3.sql查询
//第一种
// 一条
$adapter = $this->getEvent()->getApplication()->getServiceManager()->get("Zend\Db\Adapter\Adapter");
$tableGateway = new TableGateway('admin', $adapter);
$info = $tableGateway->select(['id'=>39])->current();
// 一条===链表查询
$s_name = $tableGateway->select(function ($select) use ($tmp_id) {
$select->join(
['fj' => 'atientworkannex'],
'identificationresult.workannex_id=fj.id',
['ocrset_id', 'fj_id' => 'id'],
'left'
);
$select->join(
['io' => 'ocr'],
'fj.ocrset_id=io.id',
['content', 'itemocr_id' => 'id'],
'left'
);
$select->where([
'identificationresult.id' => $tmp_id,
'identificationresult.is_del' => 0,
'fj.is_del' => 0,
'io.is_del' => 0,
]);
})->current();
4.配置使用表
//第二种
//config----
namespace Application;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Application\Service\Factory\ServiceFactory;
use Application\Service\DB\DbFactory;
'service_manager' => [
//别名
'aliases' => [
'userTable' => Service\DB\Admin\User::class,
'articleTable' => Service\DB\Admin\Article::class,
'menuTable' => Service\DB\Admin\Menu::class,
'roleTable' => Service\DB\Admin\Role::class,
'LoginModel' => Model\LoginModel::class,
],
'factories' => [
Service\DB\Admin\User::class => DbFactory::class,
Service\DB\Admin\Article::class => DbFactory::class,
Service\DB\Admin\Menu::class => DbFactory::class,
Service\DB\Admin\Role::class => DbFactory::class,
Application\Service\Db\AbstractDb::class => InvokableFactory::class,
Model\LoginModel::class => InvokableFactory::class,
],
],
//Service/DB/Admin/class-----Db类下的表
namespace Application\Service\DB\Admin;
use Application\Service\DB\AbstractDb;
use \Laminas\Db\Exception\RuntimeException;
use Laminas\Db\TableGateway\TableGateway;
class Menu extends AbstractDb {
public function __construct($dbAdapter){
$this->dbAdapter = $dbAdapter;
$this->table = new TableGateway('admin', $this->dbAdapter);
}
}
//使用类----
use Application\Service\DB\AbstractDb;
use Laminas\Db\TableGateway\TableGateway;
use Mylib\Common;
// 一条
$com = new Common();
empty($id) && $com->returnJsonArr(10001);
$tableGatewayUser = $this->LocalService('AdminUser');
$whereS = 'user_id='.$id.' and admin_userrolerelation.status = 0 and r.status=0 and r.is_del=0';
$whereU = 'id='.$id.' and is_del=0 and status=0';
$userFind = $tableGatewayUser->fetchOne($whereU);
empty($userFind) && $com->returnJsonArr(10022,'该用户不存在');
//链表查询
public function getPatientattrList($where) {
if ($where) {
return $this->table->select(function ($select) use ($where) {
$select->where($where)
->join(
['v' => 'patientattrvalue'],
'v.attr_id = patientattr.id', //链接条件
['id', 'attr_value', 'patient_id', 'var_name'],
'left'
)->columns(['attr_type', 'attr_field', 'attr_name']);
return $select;
})->toArray();
}
}
4.手动添加模块
//手动添加模块
//根目录下的/config/modules.config.php修改
//根目录下的/module/test的文件夹添加
//根目录下的/test/config/midule.config.php修改
//根目录下的/test/src/Module.php修改拟名空间名修改为test
//composer.json的引入==
//composer自动加载
//composer dump-autoload
//调试为开发模式
//composer development-enable
5.实用调试
composer:
//composer self-update
//composer clearcache
//composer update
//composer remove phpmailer/phpmailer//卸载类库
api:
//调试为开发者模式:
composer development-enable
//更新代码
composer dump-autoload