yassinedoghri/codeigniter-icons

一个基于 CodeIgniter4 的库,提供了方便的辅助函数,用于使用 yassinedoghri/php-icons 渲染 SVG 图标。

v1.0.0 2024-09-29 17:11 UTC

This package is auto-updated.

Last update: 2024-09-29 17:12:04 UTC


README

CodeIgniter Icons 🔥 🙂

一个 CodeIgniter4 库,提供了方便的辅助函数,用于使用 php-icons 渲染 SVG 图标。

Latest Stable Version Total Downloads License PHP Version Require

🚀 开始使用

0. 前提条件

使用 CodeIgniter Icons 需要以下条件

  • 基于 CodeIgniter 4.3.5+ 的项目
  • Composer 用于包管理
  • PHP 8.1+

1. 通过 Composer 安装

composer require yassinedoghri/codeigniter-icons

2. 设置

  1. 初始化并配置 PHPIcons,即创建 PHPIcons 配置文件。

  2. 将图标辅助器添加到您的 app/Config/Autoload.php 文件

public $helpers = [/*...other helpers...*/, 'icons'];

3. 使用

在您的视图文件中使用 icon(string $iconKey)phpicons(string $iconKey) 辅助函数来渲染 SVG 图标

<?= icon('material-symbols:bolt') ?>
// <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
//      <path fill="currentColor" d="m8 22l1-7H4l9-13h2l-1 8h6L10 22z"/>
// </svg>

<?= icon('material-symbols:bolt', ['class' => 'text-2xl', "style" => "color: yellow;"]) ?>
// <svg class="text-2xl" style="color: yellow;" [...]>...</svg>

<?= phpicons('material-symbols:bolt')
        ->attr('class', 'text-2xl')
        ->attr('style', 'color: yellow;') ?>
// <svg class="text-2xl" style="color: yellow;" [...]>...</svg>

有关更多信息,请参阅 php icons 文档

⚙️ 配置

查看 PHPIcons 配置参考,根据需要进行调整。

// new file - app/Config/Icons.php
<?php

declare(strict_types=1);

namespace Config;

// ...
use CodeIgniterIcons\Config\Icons as CodeIgniterIcons;

class Icons extends CodeIgniterIcons
{
    public string $phpIconsConfigPath = ROOTPATH . 'php-icons.php';
}

📜 许可证

代码在 MIT 许可证 下发布。

版权所有 (c) 2024-现在,Yassine Doghri (@yassinedoghri)。