seunex17/codeigniter4-smarty
Composer 安装命令:
composer require seunex17/codeigniter4-smarty
包简介
A smarty template engine for Codeigniter4
README 文档
README
Easily implement the Smarty templating engine in your CodeIgniter 4 project.
Description
Separate the application logic from your presentation layer in CodeIgniter 4 using this clean and semantic pre-built Smarty template.
Requirements
- Codeigniter 4.x
- Smarty 5.x
Installation
Installation is best done via Composer, you may use the following command:
composer require seunex17/codeigniter4-smarty
This will simply add the latest release of ci4-smarty as a module to your project.
Example:
By default without any additonal configuration this library will look into Views/templates/default for you template files.
Here is an example of basic usage:
- PHP:
<?php namespace App\Controllers; use Seunex17\Codeigniter4Smarty\Template\Smartie; class Home extends BaseController { public function index() { return Smartie::view('test'); } }
If you view file is in a sub directory e.g Views/dashboard/test.tpl you can load you view file like below example
- PHP:
<?php namespace App\Controllers; use Seunex17\Codeigniter4Smarty\Template\Smartie; class Home extends BaseController { public function index() { return Smartie::view('dashboard.test'); } }
To pass data from the Controller to the View:
- PHP:
<?php namespace App\Controllers; use Seunex17\Codeigniter4Smarty\Template\Smartie; class Home extends BaseController { public function index() { return Smartie::view('test', [ 'message' => 'smarty template engine', 'title' => 'Showing example on how to use smarty' ]); } }
- View
app/Views/test.tpl
<!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>{$title}</title> </head> <body> This is a message from controller: {$message} </body> </html>
Using native and custom php function in views
As at smarty v5 usage of native and custom php function as been removed. Should we need to use function in our views we need to register this functions and tell smarty we intended to use this functions.
- Publish the Smartie core config into your app
php spark smartie:publish
You publish fiel should now be located at app/Configs/Smartie.php
- Register you function
public array $modifiers = ['base_url', 'site_url'];
- Declare global variables
public array $globalVariables = ['name', 'John Doe'];
To learn more about the smarty tag you can check out the smarty official documentation here: https://smarty-php.github.io/smarty/stable/
Contributing:
All contributions are extremely appreciated.
seunex17/codeigniter4-smarty 适用场景与选型建议
seunex17/codeigniter4-smarty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「smarty」 「codeigniter4」 「seunex17」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 seunex17/codeigniter4-smarty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 seunex17/codeigniter4-smarty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 seunex17/codeigniter4-smarty 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Rewritten Smarty foreach variant that was invented for use in xoops, but nowadays is used in some other PHP based CMS'es
Modified Smarty for Rudrax
Modified Smarty for Rudrax
redbeanphp service for Rudrax
Simple ASCII output of array data
disqus library for Rudrax
统计信息
- 总下载量: 94
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-02