fis3-demo
fis3-demo copied to clipboard
fis3关于use-php这个解决方案怎么本地调试
fis3关于use-php这个解决方案怎么像fisp那样支持本地调试?
use-php只是后端资源管理的轻量级实现,并没有添加路由和数据模拟的本地调试功能。本身定位就是小项目。不过数据模拟可以通过简单的方式实现,display和widget都支持第二个参数传递页面数据,如:
//渲染首页
$debugData = json_decode(file_get_contents("./test/index.json"),true) ;
display("page/index.php",$debugData);
这样页面中就可以使用定义在test目录的模拟数据了
@zhangtao07 那再多问一句,这个支持多模块实现吗?
@FarmanYu 如果你能提供一个PHP渲染接口,可以联系我。我们团队目前有个数据模拟的解决方案 node + 任意后端语言的
url: /index.php
数据 data: 需要渲染的JSON数据 {"a":1}
模板文件名:template: index.php
模板文件根目录:template_dir: c://some/
模拟数据这样写:
$.page({
url: '/ad/create/',
title: '创建营销计划',
template: 'system/ad_create.html',
data: {
record_status: 'done',
_record_status: 'undone | checking | error | done (未备案 正在审核 备案失败 备案完成)',
record_error_msg: '广告备案审核失败原因'
}
})
@nimojs 你们的解决方案开源了吗?希望了解一下具体的做法,以及怎么被fis支持,也非常希望fis3可以自带非常方便的本地调试,多人开发将会很方便
@FarmanYu 开源的,但是最新版本在我本地。可以加我QQ联系 2049658509,正好我也想尝试支持各种情况下的页面渲染。(目前我们是 node + php + smarty 渲染)
这个解决方案是利用 node 做中间层直接调用 PHP JAVA 等后端语言实现的页面渲染接口。与FIS模拟后端模板类似,都是直接调用PHP 。
@nimojs 自己模拟了 CGI ?
@2betop 比如 node + php +smarty
一个页面渲染需要 url + data +template
127.0.0.1:1000/index.php
接收 data +template ,用smarty 根据 data 和 template 渲染,返回数据。 在 node 中书写API,然后调PHP的接口
node listen 127.0.0.1:18080
$.page({
url: '/some/',
data: {a:1},
template: 'index.html'
})
var form = {
data: settings.data,
template: settings.template,
template_dir: $._cwd + '/view/'
}
request.post({
url: '127.0.0.1:1000/index.php',
form: form
}, function (err,httpResponse,body) {
if (err) {res.send(err)}
res.send(body)
})
使用者在 node 中通过 $.page
方法快速的定义 url data template 并书写 template文件。访问 127.0.0.1:18080/url/ 时候会将 定义过的 data 和 template 发送给 /index.php ,然后在PHP中渲染页面。node接收PHP的响应内容然后再 res.send()
PHP实现的 smarty 页面渲染接口.(不熟悉PHP,下面代码应该有些性能问题。各种后端语言大致都是要实现这个接口)
<?php
date_default_timezone_set("Shanghai/Asia");
function object_array ($array) {
if(is_object($array)) {
$array = (array)$array;
}
if(is_array($array)) {
foreach ($array as $key=>$value) {
$array[$key] = object_array($value);
}
}
return $array;
}
if ($_POST['data']) {
$data = object_array(json_decode($_POST['data']));
}
$template = $_POST['template'];
$template_dir = $_POST['template_dir'];
require('lib/smarty/Smarty.class.php');
$_smarty = new Smarty();
$_smarty->setTemplateDir($template_dir);
foreach ($data as $key => $value) {
$_smarty->assign($key, $value);
}
$_smarty -> left_delimiter="{{";
$_smarty -> right_delimiter="}}";
$_smarty->display($template);
本来使用非常成熟的fisp方案挺好,无法说服后端使用smarty模板,只好使用fis3的use-php方案,略坑。
@FarmanYu 你们是前端接管后端模板的编写么?
如果是前端完全写后端模板引擎,使用 smarty 后端应该不会有反对意见
@zhangtao07 @FarmanYu ,在用模拟数据的时候,有两个考虑:
1.后端渲染模板,按 @zhangtao07 的写法,这样URL写的比较死了,后期如何做管理?用路径MAP的json配置吗?
2.ajax调用的时候,URL怎么写?这时候可能会涉及到一点,如果是后端渲染模板,那后端的请求和我这个应用,可以不在一个域内,即跨域也可以取到数据。。那ajax的时候,肯定要考虑是否同域?这时候这里的方式怎么处理比较好?
3.按照我的理解,这个use-php,和php做的项目是要分两个应用来布署了,是吧??还是怎样的理解?
多谢!