FineUI 官方论坛

标题: FineUIPHP ThinkPHP 5.1 使用教程 [打印本页]

作者: lvqingan    时间: 2019-6-13 10:34
标题: FineUIPHP ThinkPHP 5.1 使用教程
1. 安装
首先您需要按照 ThinkPHP 5.1 官方文档 的说明进行安装
假设您的安装目录是 /home/http/tp

a. 将 `FineUIPHP` 的代码解压缩到您认为合适的任意目录,您可以将代码放到项目内,也可以放到项目外

假设您的解压目录是 /home/fineui-lib

b. 修改 `composer.json` 增加下面的配置信息
  1. "repositories": [
  2. {
  3. "type": "path",
  4. "url": "../fineui-lib"
  5. }
  6. ]
复制代码
c. 执行安装命令
composer require lvqingan/fineuiphp:dev-master
2. 配置
2.1 初级化 TP 的行为
修改 `application/tags.php`
  1. 'app_init'     => [
  2. 'app\\index\\behavior\\AppInitBehavior'
  3. ],
复制代码
创建文件 `application/index/behavior/AppInitBehavior.php`
  1. <?php

  2. namespace app\index\behavior;

  3. class AppInitBehavior
  4. {
  5.     public function run()
  6.     {
  7.         // 初始化配置信息
  8.         \FineUIPHP\Config\GlobalConfig::loadConfig(array(
  9.             'Theme'           => 'Default',  // 默认主题
  10. 'ResourceHandler' => 'index/index/res'  // 资源文件获取入口
  11. ));
  12. }
  13. }
复制代码
2.2 配置 View Filter
由于 TP 5.1.3 里面把 `view_filter` 已经移除了,所以只能通过 `Controller` 的 `initialize` 来实现

创建文件 `application/index/controller/BaseController.php`
  1. <?php

  2. namespace app\index\controller;

  3. use think\Controller;

  4. abstract class BaseController extends Controller
  5. {
  6.     protected function initialize()
  7.     {
  8.         parent::initialize();

  9.         $this->view->filter(function($content){
  10. return \FineUIPHP\ResourceManager\ResourceManager::finish($content);
  11. });
  12. }
  13. }
复制代码
并将 `application/index/controller/Index.php` 的父类改为 `BaseController`
3. 静态资源入口文件

在 `application/index/controller/Index.php` 中增加方法,对应到 `AppInitBehavior.php` 中 `ResourceHandler` 配置的地址
`index/index/res`

  1. public function res()
  2. {
  3. $handler = new \FineUIPHP\ResourceManager\ResourceHandler();

  4. $handler->ProcessRequest();
  5. }
复制代码
4. 演示例子

在 `application/index/controller/Index.php` 修改方法 `index`

  1. public function index()
  2. {
  3. return $this->fetch();
  4. }
复制代码
并创建模板 `application/index/view/index/index/index.html`
  1. <html>
  2. <head>
  3.     <title>ThinkPHP 3.2 使用教程</title>
  4. </head>
  5. <body style="padding: 20px;">
  6. <?php
  7. echo \FineUIPHP\FineUIControls::textBox()->text('默认文字');
  8. echo '<hr/>';
  9. echo \FineUIPHP\FineUIControls::button()->text('提交');
  10. ?>
  11. </body>
  12. </html>
复制代码


https://github.com/lvqingan/fineuiphp-demo-thinkphp-5.1






欢迎光临 FineUI 官方论坛 (https://www.fineui.com/BBS/) Powered by Discuz! X3.4