fis-plus icon indicating copy to clipboard operation
fis-plus copied to clipboard

fis-plus如何与后端结合使用

Open hefangshi opened this issue 10 years ago • 1 comments

fis-plus实际上是fis+php+smarty的技术选型,无论是thinkphp还是yaf还是其他任何php框架,只要渲染引擎选择用smarty,就可以无缝兼容。

前端与后端结合的关键点就在于要把fis-plus产出的config目录在后端smarty配置里设置为config_dir ,template目录设置为template_dir,plugin目录设置为plugins_dir,然后后端渲染数据的时候设置好tpl路径即可。

此外还可以通过配置fis-plus让其产出目录适应后端目录结构,并不局限于通过后端目配置来适应前端目录结构。

比如以下是fisp的内置服务的index.php中加载smarty的实现,在加载完smarty后,只需要后端同学指定了正确的render模板并给予正确的模板数据,就可以实现前后端的结合。

    require_once ($root . 'smarty/Smarty.class.php');
    $smarty = new Smarty();
    $default_conf = array(
        'template_dir' => 'template',
        'config_dir' => 'config',
        'plugins_dir' => array( 'plugin' ),
        'left_delimiter' => '{%',
        'right_delimiter' => '%}'
    );
    if(file_exists($root . 'smarty.conf')){
        $user_conf = parse_ini_file($root . 'smarty.conf');
        if(!empty($user_conf)){
            $default_conf = array_merge($default_conf, $user_conf);
        }
    }
    $smarty->setTemplateDir($root . $default_conf['template_dir']);
    $smarty->setConfigDir($root . $default_conf['config_dir']);
    foreach ($default_conf['plugins_dir'] as $dir) {
        $smarty->addPluginsDir($root . $dir);
    }
    $smarty->setLeftDelimiter($default_conf['left_delimiter']);
    $smarty->setRightDelimiter($default_conf['right_delimiter']);

hefangshi avatar Jun 06 '14 10:06 hefangshi

是有前端在本地开发环境编写 smarty 模板,并约定渲染的数据源。然后让后端同事指定模板和数据源进行渲染?

前端在本地就写这样的 smarty模板?

<!-- 渲染方式:Smart 模板渲染 -->
{include file="header_1.tpl"}
<title>页面标题</title>
{include file="header_2.tpl"}
<ul>
    <li>
    欢迎你,
    {if $status=='free'}
        普通会员
    {else}
        会员
    {/if}
    {username}
    </li>
    {if $status=='free'}
        <li><a href="/email/">收取邮件</a></li>
    {/if}
    {username}
</ul>
{include file="footer.tpl"}

nimoc avatar Mar 29 '15 13:03 nimoc