当前位置: 首页 > news >正文

如何做网站进行推广做seo网站诊断书怎么做

如何做网站进行推广,做seo网站诊断书怎么做,云南住建局和城乡建设报考网站,电脑上用手机app是什么软件学习路之PHP--easyswoole使用视图和模板 一、安装依赖插件二、 实现渲染引擎三、注册渲染引擎四、测试调用写的模板五、优化六、最后补充 一、安装依赖插件 composer require easyswoole/template:1.1.* composer require topthink/think-template相关版本#xff1a; … 学习路之PHP--easyswoole使用视图和模板 一、安装依赖插件二、 实现渲染引擎三、注册渲染引擎四、测试调用写的模板五、优化六、最后补充 一、安装依赖插件 composer require easyswoole/template:1.1.* composer require topthink/think-template相关版本 easyswoole/easyswoole: 3.3.x,easyswoole/orm: ^1.5,easyswoole/template: 1.1.*,topthink/think-template: ^2.0二、 实现渲染引擎 在 App 目录下 新建 System 目录 存放 渲染引擎实现的代码 ThinkTemplate.php ?php namespace App\System;use EasySwoole\Template\RenderInterface; use think\facade\Template;class ThinkTemplate implements RenderInterface {// tp模板类对象private $_topThinkTemplate;public function __construct(){$temp_dir sys_get_temp_dir();$config [view_path EASYSWOOLE_ROOT . /App/HttpTemplate/, // 模板存放文件夹根目录cache_path $temp_dir, // 模板文件缓存目录view_suffix html // 模板文件后缀];$this-_topThinkTemplate new \think\Template($config);}public function afterRender(?string $result, string $template, array $data [], array $options []){}// 当模板解析出现异常时调用public function onException(\Throwable $throwable): string{$msg $throwable-getMessage() . is file . $throwable-getFile() . of line . $throwable-getLine();return $msg;}// 渲染逻辑实现public function render(string $template, array $data [], array $options []): ?string{foreach ($data as $k $v) {$this-_topThinkTemplate-assign([$k $v]);}// Tp 模板渲染函数都是直接输出 需要打开缓冲区将输出写入变量中 然后渲染的结果ob_start();$this-_topThinkTemplate-fetch($template);$content ob_get_contents();ob_end_clean();return $content;} }由于版本问题报错 ?php namespace App\System;use EasySwoole\Template\RenderInterface; use think\facade\Template;class ThinkTemplate implements RenderInterface {// tp模板类对象private $_topThinkTemplate;public function __construct(){$temp_dir sys_get_temp_dir();$config [view_path EASYSWOOLE_ROOT . /App/HttpTemplate/, // 模板存放文件夹根目录cache_path $temp_dir, // 模板文件缓存目录view_suffix html // 模板文件后缀];$this-_topThinkTemplate new \think\Template($config);}public function afterRender(?string $result, string $template, array $data [], array $options []){}// 当模板解析出现异常时调用// public function onException(\Throwable $throwable): string// {// $msg $throwable-getMessage() . is file . $throwable-getFile() . of line . $throwable-getLine();// return $msg;// }// 渲染逻辑实现// public function render(string $template, array $data [], array $options []): ?string// {// foreach ($data as $k $v) {// $this-_topThinkTemplate-assign([$k $v]);// }// // Tp 模板渲染函数都是直接输出 需要打开缓冲区将输出写入变量中 然后渲染的结果// ob_start();// $this-_topThinkTemplate-fetch($template);// $content ob_get_contents();// ob_end_clean();// return $content;// }public function render(string $template, ?array $data null, ?array $options null): ?string{// return your template is {$template} and data is . json_encode($data);foreach ($data as $k $v) {$this-_topThinkTemplate-assign([$k $v]);}// Tp 模板渲染函数都是直接输出 需要打开缓冲区将输出写入变量中 然后渲染的结果ob_start();$this-_topThinkTemplate-fetch($template);$content ob_get_contents();ob_end_clean();return $content;}public function onException(\Throwable $throwable, $arg): string{// return $throwable-getTraceAsString();$msg $throwable-getMessage() . is file . $throwable-getFile() . of line . $throwable-getLine();return $msg;} } 三、注册渲染引擎 需要对模板引擎进行实例化并且注入到EasySwoole 的视图中 在项目根目录 EasySwooleEvent.php 中 mainServerCreate 事件函数中进行注入代码如下 use App\System\ThinkTemplate; use EasySwoole\Template\Render; use EasySwoole\Template\RenderInterface; // 设置Http服务模板类 Render::getInstance()-getConfig()-setRender(new ThinkTemplate()); Render::getInstance()-getConfig()-setTempDir(EASYSWOOLE_TEMP_DIR); Render::getInstance()-attachServer(ServerManager::getInstance()-getSwooleServer());四、测试调用写的模板 在App目录下创建 HttpTemplate 目录 PS:之前在 ThinkTemplate.php 文件中设置的路径 创建文件 /App/HttpTemplate/Admin/Index/index.html 路径与模块 控制器 响应函数相对应 你也可以按照自己的喜欢来 !DOCTYPE html html langen headmeta charsetUTF-8titletao/title /head body ul{foreach $user_list as $key $val}li{$key} {$val}/li{/foreach} /ul /body /html在 App\HttpController\Admin 中调用 use EasySwoole\Template\Render; public function index(){$user_list [1, 2, 3, 4, 5];$this-response()-write(Render::getInstance()-render(Index/index, [user_list $user_list]));}五、优化 这样的模板传值非常麻烦有木有 还必须要放在一个数组中一次性传给 Render 对象 我们可以将操作封装到基类控制器 实现类似于TP框架的操作 代码如下 ?php /*** 基础控制器类*/ namespace App\HttpController;use EasySwoole\Template\Render;abstract class Controller extends \EasySwoole\Http\AbstractInterface\Controller {public $template_data [];public function assign($name, $value) {$this-template_data[$name] $value;}public function fetch($template_name) {return Render::getInstance()-render($template_name, $this-template_data);} }这样我们就可以使用TP的风格进行模板传值了 效果和上面时一样的 PS:暂时需要指定模板的路径 function index(){$user_list [1, 2, 3, 4, 5];$this-assign(user_list, $user_list);$this-response()-write($this-fetch(Index/index));}六、最后补充 EasySwooleEvent.php ?php namespace EasySwoole\EasySwoole;use EasySwoole\EasySwoole\Swoole\EventRegister; use EasySwoole\EasySwoole\AbstractInterface\Event; use EasySwoole\Http\Request; use EasySwoole\Http\Response; use App\Process\HotReload; use EasySwoole\ORM\DbManager; use EasySwoole\ORM\Db\Connection; use App\System\ThinkTemplate; use EasySwoole\Template\Render; use EasySwoole\Template\RenderInterface;class EasySwooleEvent implements Event {public static function initialize(){// TODO: Implement initialize() method.date_default_timezone_set(Asia/Shanghai);$config new \EasySwoole\ORM\Db\Config(Config::getInstance()-getConf(MYSQL));DbManager::getInstance()-addConnection(new Connection($config));}public static function mainServerCreate(EventRegister $register){// TODO: Implement mainServerCreate() method.$swooleServer ServerManager::getInstance()-getSwooleServer();$swooleServer-addProcess((new HotReload(HotReload, [disableInotify false]))-getProcess());Render::getInstance()-getConfig()-setRender(new ThinkTemplate());Render::getInstance()-getConfig()-setTempDir(EASYSWOOLE_TEMP_DIR);Render::getInstance()-attachServer(ServerManager::getInstance()-getSwooleServer());}public static function onRequest(Request $request, Response $response): bool{// TODO: Implement onRequest() method.return true;}public static function afterRequest(Request $request, Response $response): void{// TODO: Implement afterAction() method.} }App\System\ThinkTemplate.php ?php namespace App\System;use EasySwoole\Template\RenderInterface; use think\facade\Template;class ThinkTemplate implements RenderInterface {// tp模板类对象private $_topThinkTemplate;public function __construct(){$temp_dir sys_get_temp_dir();$config [view_path EASYSWOOLE_ROOT . /App/HttpTemplate/, // 模板存放文件夹根目录cache_path $temp_dir, // 模板文件缓存目录view_suffix html // 模板文件后缀];$this-_topThinkTemplate new \think\Template($config);}public function afterRender(?string $result, string $template, array $data [], array $options []){}// 当模板解析出现异常时调用// public function onException(\Throwable $throwable): string// {// $msg $throwable-getMessage() . is file . $throwable-getFile() . of line . $throwable-getLine();// return $msg;// }// 渲染逻辑实现// public function render(string $template, array $data [], array $options []): ?string// {// foreach ($data as $k $v) {// $this-_topThinkTemplate-assign([$k $v]);// }// // Tp 模板渲染函数都是直接输出 需要打开缓冲区将输出写入变量中 然后渲染的结果// ob_start();// $this-_topThinkTemplate-fetch($template);// $content ob_get_contents();// ob_end_clean();// return $content;// }public function render(string $template, ?array $data null, ?array $options null): ?string{// return your template is {$template} and data is . json_encode($data);foreach ($data as $k $v) {$this-_topThinkTemplate-assign([$k $v]);}// Tp 模板渲染函数都是直接输出 需要打开缓冲区将输出写入变量中 然后渲染的结果ob_start();$this-_topThinkTemplate-fetch($template);$content ob_get_contents();ob_end_clean();return $content;}public function onException(\Throwable $throwable, $arg): string{// return $throwable-getTraceAsString();$msg $throwable-getMessage() . is file . $throwable-getFile() . of line . $throwable-getLine();return $msg;} } App\HttpController\Index.php ?phpnamespace App\HttpController;use EasySwoole\Template\Render;class Index extends BaseController {/*** */public function index(){$user_list [1, 2, 3, 4, 5];$this-assign(user_list, $user_list);$this-response()-write($this-fetch(Index/index));}}App\HttpController\BaseController.php ?php /*** 基础控制器类*/ namespace App\HttpController;use EasySwoole\Template\Render;abstract class BaseController extends \EasySwoole\Http\AbstractInterface\Controller {public $template_data [];public function assign($name, $value) {$this-template_data[$name] $value;}public function fetch($template_name) {return Render::getInstance()-render($template_name, $this-template_data);} } App\HttpTemplate\Index\index.html !DOCTYPE html html langen headmeta charsetUTF-8title视频模板测试/title /head body ul{foreach $user_list as $key $val}li{$key} {$val}/li{/foreach} /ul /body /html
http://www.zqtcl.cn/news/836347/

相关文章:

  • 网站首页设计注意斗蟋蟀网站建设
  • 石家庄网站建设远策科技网站建设公司人员配备
  • 手机怎么建网站链接专门做鞋子的网站吗
  • 网站建设设计作品怎么写网站建设 网站内容 采集
  • 自己做网站nas如何做网站大图片
  • 网站优化定做嘉兴模板建站代理
  • 南宁做网站比较好的公司有哪些花乡科技园区网站建设
  • 网站注册平台怎么注册申请空间 建立网站吗
  • 汕头住房与城乡建设网站做网站视频 上传到哪儿
  • 东莞网站关键词优化福建个人网站备案
  • 国外获奖flash网站泉州网站制作专业
  • 万网域名注册后如何做网站教学上海app开发和制作公司
  • 恩施网站建设公司个人网站怎么制作成图片
  • 泸州高端网站建设公司上海企业网站
  • wordpress 建站 知乎济南全包圆装修400电话
  • 织梦建设两个网站 视频影视公司宣传片
  • 北京小企业网站建设那个做网站好
  • 怎样用模块做网站深圳网站建设制作厂家
  • 网站项目中的工作流程网站建设社区
  • 建设厅网站查询电工证件提供网站建设公司哪家好
  • 免费网站软件下载安装称多网站建设
  • 网站客户续费深圳福田地图
  • 连云港做电商网站的公司营销公司网站模板
  • 沈阳企业网站优化排名方案富阳做网站公司
  • 企业网站优化报价自己做个网站怎么赚钱
  • 做ui的网站有哪些网站建设订单模板
  • 重庆企业网站优化wordpress 接收询盘
  • 小米4路由器可以做网站嘛杭州淘宝代运营公司十大排名
  • 枞阳做网站的百度搜索入口
  • 网站建设提议徐州网站建设方案咨询