matycz / lemo-theme
4.0.1
2021-06-09 07:00 UTC
Requires
- php: ^7.4 || ^8.0
- laminas/laminas-dependency-plugin: ^2.0
- laminas/laminas-eventmanager: ^3.0
- laminas/laminas-mvc: ^3.0
- laminas/laminas-servicemanager: ^3.0
- laminas/laminas-stdlib: ^3.0
- laminas/laminas-view: ^2.0
Requires (Dev)
- vimeo/psalm: ~4.7.0
README
Lemo\Theme 是一个允许你在各种主题之间切换的 Zend Framework 2 模块。它允许你创建各种主题,并在它们之间进行切换。主题可以安装在不同的文件夹中。
当前主题可以在全局的 global.ini
或 local.ini
中定义,以应用于整个应用程序。对于该模块,你可以在 module.config.php
中设置默认主题。您也可以通过 ServiceManager
从 ThemeManager
实例切换主题。
安装
此模块的安装使用 composer。有关 composer 的文档,请参阅 getcomposer.org。
-
cd my/project/directory
-
创建一个包含以下内容的
composer.json
文件{ "require": { "matycz/lemo-theme": ">=1.0" } }
-
运行
php composer.phar install
-
打开
my/project/directory/config/application.config.php
并将模块名称Lemo\Theme
添加到modules
键中,如下所示return array( ... 'modules' => array( ... 'Lemo\Theme' ... ), ... );
不使用 composer 的安装不受官方支持,并且需要您安装并自动加载在 composer.json
中指定的依赖项。
文档
在配置文件中,您可以设置要使用的默认主题,以及以下列出的用于选择当前主题的目录列表
'theme_manager' => array(
'theme' => 'default',
'theme_paths' => array(
'./theme/'
),
),
要快速设置基本主题,您可以只需将 examples/theme
文件夹中的 default
主题复制到应用程序根目录下的 theme
文件夹,或者根据以下教程创建一个新的主题。确保将 theme
选项设置为您的主题名称。
示例
<?php namespace Foo\Controller; use Lemo\Theme\ThemeManagerInterface; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\ViewModel; class BarController extends AbstractActionController { /** * @var ThemeManagerInterface */ protected $themeManager; ... /** * Page with grid example * * @return ViewModel */ public function indexAction() { // Example1 - Set new theme with name foo $this->getThemeManager()->setTheme('foo'); // Example 2 - Set new theme with name foo $this->getServiceLocator()->get('ThemeManager')->setTheme('foor'); return new ViewModel(array( ... )); } ... /** * @param ThemeManagerInterface $themeManager * @return BarController */ public function setThemeManager(ThemeManagerInterface $themeManager) { $this->themeManager = $themeManager; return $this; } /** * @return ThemeManagerInterface */ public function getThemeManager() { return $this->themeManager; } }
<p class="current-theme"><?= $this->theme() ?></p>