FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 3209|回复: 0

FineUIPHP ThinkPHP 5.1 使用教程

[复制链接]
发表于 2019-6-13 10:34:33 | 显示全部楼层 |阅读模式
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 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-3-29 07:25 , Processed in 0.044348 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表