jxy918/swoft-smarty 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jxy918/swoft-smarty

Composer 安装命令:

composer require jxy918/swoft-smarty

包简介

smarty view base on swoft

README 文档

README

Latest Stable Version Php Version Swoft Doc Swoft License

sowft框架smarty模板组件

smarty template component for swoft.

Swoft-smarty Component

Install, 安装

  • composer install command
composer require jxy918/swoft-smarty

  • smarty default config
  • swoft框架里 smarty 的默认配置如下, 默认不需要添加, 如果想要修改, 可以把下面配置放入到bean.php里面, 进行相应的修改即可
'smarty' => [
    'debugging'=>true,
    'caching'=>true,
    'cacheLifetime'=>120,
    'leftDelimiter' => '<!--{',
    'rightDelimiter' => '}-->',
    'templateDir' => '@base/resource/template',
    'compileDir' => '@base/runtime/template_c',
    'cacheDir' => '@base/runtime/cache'
]

Use in Controller, 控制器里使用如下

  • app/Http/Controlle/SmartyController.php
  • resource/template/smarty.html

app/Http/Controlle/SmartyController.php

<?php declare(strict_types=1);


namespace App\Http\Controller;

use Swoft;
use ReflectionException;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Http\Message\ContentType;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;

/**
 * Class SmartyController
 *
 * @since 2.0
 *
 * @Controller(prefix="smarty")
 */
class SmartyController
{
    /**
     * @RequestMapping("index")
     * @return Response
     * @throws ContainerException
     * @throws ReflectionException
     * @throws \Swoft\Exception\SwoftException
     */
    public function assign(): Response
    {
        $tpl = Swoft::getBean('smarty')->initView();
        $data = ['nickname'=>'jxy918', 'sex'=>'男', 'msg'=>' hello smarty'];
        $tpl->assign('data', $data);
        $content = $tpl->fetch('smarty.html');
        return context()->getResponse()->withContentType(ContentType::HTML)->withContent($content);
    }
}


模板文件 resource/template/smarty.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>test smayrt</title>
</head>
<body>
<div>
    <div>
        <h1>Hello Smarty</h1>
    </div>
    <ul>
        <!--{foreach key=k item=v from=$data}-->
        <li><!--{$k}-->:<!--{$v}--></li>
        <!--{/foreach}-->
    </ul>
</div>
</body>
</html>

统计信息

  • 总下载量: 67
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固