douye2110 2011-01-09 20:03
浏览 31
已采纳

Smarty,子目录中的页面

i am trying to figure out how to hold pages in subdirectories (categories) using php Smarty template engine.

For instance if my structure is:

index.php
category1/page1.php
category2/page2.php

etc.

the root index.php is rendering just fine

using the default smarty setup:

<?php 
require_once('lib/smtemplate.php');

$data = array(
    'meta_keywords' =>'key1, key2',
    'category' =>'category1'
    );

$tpl = new SMTemplate();
$tpl->render('page', $data);

?>

but if i copy it into subdirectory it breaks even if i change to

require_once('../lib/smtemplate.php');

and i cant find a solution so far.

Appreciate your help. thx.

  • 写回答

1条回答 默认 最新

  • douhanxujiuji6098 2011-01-09 20:05
    关注

    Define a basepath:

    define("BASEPATH", "/var/www/yoursite/");
    

    And include like this:

    require_once(BASEPATH.'lib/smtemplate.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理