承接 tatter/themes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tatter/themes

Composer 安装命令:

composer require tatter/themes

包简介

Lightweight theme manager for CodeIgniter 4

README 文档

README

Lightweight theme manager for CodeIgniter 4

Coverage Status

Quick Start

  1. Install with Composer: > composer require tatter/themes
  2. Update the database: > php spark migrate -all
  3. Seed the database: > php spark db:seed "Tatter\Themes\Database\Seeds\ThemeSeeder"
  4. Place theme files in public/assets/themes/default
  5. Add theme files to your page, e.g.: echo view('\Tatter\Themes\Views\css)

Features

Provides convenient theme file organization and display for CodeIgniter 4

Installation

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

  • > composer require tatter/themes

Or, install manually by downloading the source files and adding the directory to app/Config/Autoload.php.

Once the files are downloaded and included in the autoload, run any library migrations to ensure the database is setup correctly:

  • > php spark migrate -all

You will also need to seed the database with a default theme:

  • > php spark db:seed "Tatter\Themes\Database\Seeds\ThemeSeeder"

Dependencies

Themes relies heavily on these libraries; be sure you are familiar with their own requirements and installation process.

If you plan on allowing users to change their own themes then you will also need to include an authentication library the provides codeigniter4/authentication-implementation (no other configuration necessary).

Read more about CodeIgniter Authentication in the User Guide.

Usage

This library assumes you already have the asset files (CSS and JavaScript) used by your themes.

Themes are managed via the database and configured for your application using Filters.

Managing Themes

Theme files all go into a directory relative to the config property $directory from Tatter\Assets (default is public/assets/), as defined by a theme's path. E.g.

  • public/assets/themes/default/styles.css
  • public/assets/themes/default/script.js
  • public/assets/themes/dark/header.css
  • public/assets/themes/dark/fonts.css
  • public/assets/themes/perky/Perky.CSS

Each theme is an entry in the database themes table with the following properties:

  • name: A short, unique name used for theme lookup and display, e.g. "Aquatic Journey"
  • path: The path (relative to the Assets directory) to the publicly-available theme files, e.g. "themes/aquatic/"
  • description (optional): A brief description of this theme's features, mostly useful for allowing user selection, e.g. "A blue theme with deep hues and liquid borders"
  • dark: Whether this theme is dark (light text, dark backgrounds) or not, e.g. true

You may use the supplied model (Tatter\Themes\Models\ThemeModel) to create new themes or return entities (Tatter\Themes\Entities\Theme). The library comes with the ThemeSeeder which will create an initial "Default" theme for you at public/assets/themes/default/. There is also a themes:add Spark command to guide you through loading themes from CLI.

Selecting a Theme

The current theme is determined as follows:

  1. Is there an authenticated user? Check Preferences for that user's theme preference
  2. No authenticated user? Check the Session for a theme preference
  3. Neither of above? Check Settings for a stored persistent theme
  4. None of the above? Fall back on the config file: config('Preferences')->theme (default value "Default")

Likewise, you can set the current theme using the corresponding methods (in priority order):

  1. preference('theme', $themeName) (with authenticated user)
  2. preference('theme', $themeName) (without authenticated user)
  3. setting('Preferences.theme, $themeName)
  4. Create or edit app/Config/Preferences.php and add: public $theme = 'theme_name';

To assist with methods 1 & 2 this library comes with a tiny module to display a form and process user input. You can add the form to an existing page with the Form View:

<div class="form">
	<?= view('Tatter\Themes\Views\form') ?>
</div>

...or add the preconfigured <select> field to an existing form:

<form name="user-settings" action="<?= site_url('users/settings') ?>" method="post">
	Display name:
	<input type="text" name="name">

	Page theme:
	<?= view('Tatter\Themes\Views\select') ?>

	<input type="submit" value="submit">
</form>

You can pass these additional parameters to the view:

  • $class: A CSS class to apply to the <select> field. Default: none
  • $auto: Whether the form should submit as soon as the select field is changed. Default: true
  • $selected: The theme to show as currently chosen in the select field: Default: current theme

Applying Themes

Once your files are in place and your theme is defined in the database you need to apply the theme to your application routes using Filters. This library activates the ThemesFilter for you on installation (assuming module discovery is enabled, which is the default) under the alias themes. In simple cases you will want to apply the filter to your entire site via app/Config/Filters.php:

    /**
     * List of filter aliases that are always
     * applied before and after every request.
     *
     * @var array
     */
    public $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
        ],
        'after' => [
            'themes',
        ],
    ];

For more nuanced use, pass the filter to your route definitions in app/Config/Routes.php:

$routes->add('shop/(:segment)', 'ShopController::index', ['filter' => 'themes']);

ThemesFilter will apply the current theme by default, but you may specify a theme or themes by name to use those instead:

$routes->add('heroes/(:segment)', 'HeroController::$1', ['filter' => 'themes:Heroic']);

Additional Components

CLI

The library comes with two CLI commands, themes:list and themes:add to ease working with themes in the database.

Helper

The Theme Helper is loaded automatically when you apply ThemeFilter, but should you need to load it manually include it your controllers or boot config: helper('themes').

This provides a helper function to return the current theme as a Theme entity:

$theme = theme();
echo 'Current theme is ' . $theme->name . ': "' . $theme->description . '"';

tatter/themes 适用场景与选型建议

tatter/themes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.31k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2019 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「themes」 「css」 「codeigniter」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tatter/themes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tatter/themes 我们能提供哪些服务?
定制开发 / 二次开发

基于 tatter/themes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 18
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-20