kykurniawan / rangkai
一个极简的PHP布局库
v1.0.0
2022-04-22 07:59 UTC
Requires
- laminas/laminas-escaper: 2.10.x-dev
README
Rangkai 是从流行的框架 CodeIgniter 4 中提取的布局库。Rangkai 设计用于在 BuahNaga 网络框架 中重复使用,以进行页面布局和渲染过程。
安装 Rangkai
您可以通过运行以下 composer 安装命令轻松地将 Rangkai 库添加到 PHP 项目中
composer require kykurniawan/rangkai
确保您从 vendor 文件夹加载了自动加载文件。安装完成后,您可以通过以下方式显示页面。
<?php use Kykurniawan\Rangkai\Rangkai; // Create new Rangkai instance with provided views path where we store the view file. $rangkai = new Rangkai('Views'); // Set some data to our view $rangkai->setData(['name' => 'Gumbili Project']); // Display our view with echo // Note: "page" is file path relative to views path // if your page in Views/home/page.php, you should use "home/page" instead of "page" echo $rangkai->render('page'); ?>
布局
Rangkai 为您的项目提供基本的布局功能,简单但实用。
创建布局
要创建布局,请在创建新的 Rangkai 实例之前(在创建 Rangkai 实例时定义)在视图文件夹中创建一个新的 PHP 文件
<!-- layout.php --> <html> <head> <title>Rangkai</title> </head> <body> <header> <!-- Assume your header here --> </header> <main> <!-- Here we will place the content --> <?php $this->renderSection('content') ?> </main> <footer> <!-- Assume your footer here --> </footer> </body> </html>
扩展布局
<!-- home.php --> <?php $this->extend('layout') ?> <?php $this->section('content') ?> <div> <h1>Hello World!</h1> </div> <?php $this->endSection() ?>
包含布局
要包含布局,只需写入以下示例中描述的一行代码
<?php $this->include('path to your view file without extension') ?>
示例
<!-- layout.php --> <html> <head> <title>Rangkai</title> </head> <body> <header> <!-- We are including header here --> <?php $this->include('header') ?> </header> <main> <!-- Here we will place the content --> <?php $this->renderSection('content') ?> </main> <footer> <!-- We are including footer here --> <?php $this->include('footer') ?> </footer> </body> </html>
许可
MIT License
Copyright (c) 2022 Gumbili Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.