ox-harris / phpfront
phpFront 是一个基于 DOM 的服务器端模板引擎。它实现了 jQuery API,具有强大的 CSS3 选择器和链式方法。它在服务器端渲染和 Web 开发中的模板操作方面进行了大量优化。(没有模板语法 - 因为我们像其他人一样讨厌它们)
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2021-10-26 08:24:26 UTC
README
PHPFront 将帮助您在 PHP 应用程序中读取/写入 HTML 模板中的内容,读取/写入属性,遍历整个文档,动态地操作元素(创建、重复、导入、移动、替换、删除),生成一个干净的 HTML 输出,代表您的整个应用程序。这是服务器端渲染。
它实现了 jQuery API,具有其强大的 CSS3 选择器和链式方法。它经过良好测试,为网站和其他基于 PHP 的应用程序进行了大量优化;充满爱意地构建,为您的代码带来所有轻松和乐趣,以及许多新的可能性!
安装
需求
PHPFront 需要 PHP 5.3 或更高版本的 Web 服务器。
安装
有两种选择
使用 Composer
composer require ox-harris/phpfront
从 GitHub
从 GitHub 下载:github.com/ox-harris/phpfront/releases
解压 PHPFront 的 zip 文件,您会发现名为‘lib’的最重要文件夹。此文件夹包含核心工作文件。此文件夹及其内容是您不应该编辑的东西。
将 PHPFront 文件夹移动到项目的 frontend 目录或项目根目录下的任何位置 - 具体取决于应用程序的目录结构。只需确保您的应用程序的自动加载器在调用时可以拾取 PHPFront 类 - 如果您的项目捆绑了自动加载器,则只需简单地将 PHPFront 文件的路径记录下来,以便在设置期间手动包含此路径。
测试
要查看 PHPFront 是否可用于使用,请使用 PHPFront::info()
。这应该显示几行信息。如果您只想测试 PHPFront 或如果您的项目只是基本的,以下是一个按编号步骤设置的测试用例。
- 创建一个名为‘app.php’的新 PHP 文件 - 这里只是为了这个例子。
- 将 PHPFront 文件夹复制到与 app.php 文件相同的目录。
- 创建一个名为‘template.html’的纯 HTML 页面 - 一个不包含任何 PHP 标签的页面 - 并将文件放入此目录。
然后在您的 app.php 中
-
包含 PHPFront 类。
Include ‘PHPFront/lib/PHPFront.php’; // If you stored the PHPFront folder in a different location, your include path would change. // Where ‘path-to-PHPFront’ is your actual path to where you stored PHPFront Include ‘path-to-PHPFront/PHPFront/lib/PHPFront.php’;
-
现在 PHPFront 可用于我们的 app.php 脚本,因此我们实例化它
$PHPFront = new PHPFront;
-
现在,我们将模板交给 PHPFront 使用 - 我们的 template.html 页面
$PHPFront->setTemplate(‘template.html’); // If your stored template.html in a different location, your path would change. // Where ‘path-to-template is your actual path to where you stored template.html $PHPFront->setTemplate(‘path-to-template/template.html’);
-
现在我们可以使用CSS3选择器开始读取和写入模板中相应元素的内容
// For document title (title) $PHPFront->find(‘title’)->html(‘This is document title’); // For page heading 1 (h1) $PHPFront->find(‘h1’)->html(‘Hello World!’); // For page paragraph (p) $PHPFront->find(‘p’)->html(‘Here is my first PHPFront project’)->addClass('rounded-corners')->css('color', 'gray'); // Load a HTML fragment into a DIV and manipulate its content $PHPFront->find('#container')->load(__DIR__.'/templates/table.html')->find('tr:even')->css('background-color', 'whitesmoke') ->parents('table')->attr('id', 'employee-table')->append('<tr><td>342</td><td>John Doe</td></tr>');
-
最后,我们使用PHPFront的render()函数来渲染我们的页面
$PHPFront->render();
这就完成了!在浏览器中预览您的app.php,体验PHPFront在您项目中的简洁和优雅!
文档
https://ox-harris.github.io/phpfront/documentation/ (适用于phpFront v1.0.0)
反馈
所有错误、功能请求、pull请求、反馈等,都欢迎提出。 创建问题。
跟进
https://www.twitter.com/PHPFront.
作者
Oxford Harrison ox_harris@yahoo.com
许可
GPL-3.0 - 查看 LICENSE