[求助] Smarty模板include PHP文件出现的问题

  这个问题困绕我两天了,GOOGLE,BAIDU了无数次,还是没有结果,请各位帮帮忙,不胜感激。

  情况是这样的,我以前用PHP写了一个投票系统,想直接调用到首页使用,结果就出现了问题。数据库内容无法显示出来。


代码部分:

index.php代码就只是调用了Smarty代码如下:

[复制到剪切板]
CODE:
//-------------------------------//
//   index.php 程序代码 //
//-------------------------------//
require_once('Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir 'template/default';  //模板文件夹
$smarty->compile_dir 'compile';  //编译文件夹
$smarty->config_dir 'config';
$smarty->cache_dir 'cache';
$smarty->display('index.htm'); ;

在模板文件index.htm中包含votes.php的代码如下:

[复制到剪切板]
CODE:
//--------------------------------//
//   index.htm 模板代码  //
//--------------------------------//
{include_php file="votes.php"} ;

votes.php是没有问题,但是显示和投票是写在一个页里的,很杂乱,代码大概如下:

[复制到剪切板]
CODE:
//--------------------------------//
//   votes.php 模板代码  //
//--------------------------------//

//定义动作页
$action  $_GET['action'];
switch(
$action)
{
    case 
'show'showVotes(); break;  //处理投票和显示投票结果页面
    
default: votes();  //显示投票页面
}

//显示投票页面
function votes()
{
     
……代码……
}

//处理投票和显示投票结果页面
function showVotes()
{
     
……代码……
} ;

显示部分:

直接用votes.php的话,可以正常显示:
引用:
//--------------------------------//
//   votes.php 显示结果  //
//--------------------------------//

《投票主题》

·选项一
·选项二
·选项三

[投票][查看]
Smarty后index.php包含votes.php显示不正常
引用:
//--------------------------------//
//   votes.php 显示结果  //
//--------------------------------//

《投票主题》

[投票][查看]
注意不正常的地方:选项没有显示!?


有点乱,总结一下:

1、Smarty模板的使用经过调试是正常的,没有问题。
2、votes.php投票系统单独运行的话是正常的,没有问题。
3、无论是Smarty还是PHP都没有报错,说明程序和路径都正常,没有问题。

问题在这里:
index.php使用模板index.htm包含votes.php时,votes.php无法正常工作。


补充测试部分:

我查看过了compile文件夹(即smarty默认template_c文件夹)下编译过的index.php文件(%%43^43B^43B32F4B%%index.htm.php)代码,它把{include_php file="votes.php"}生成了如下代码:

[复制到剪切板]
CODE:
require_once(SMARTY_CORE_DIR 'core.smarty_include_php.php');
smarty_core_smarty_include_php(array('smarty_file' => "votes.php"'smarty_assign' => '''smarty_once' => false'smarty_include_vars' => array()), $this); ;

我将以上代码替换成了:

[复制到剪切板]
CODE:
include("votes.php"); ;

votes.php依然无法正常工作。

如果不用Smarty编译,直接在index.php中使用:

[复制到剪切板]
CODE:
include("votes.php"); ;

votes.php就可以正常工作了。

这说明错误的根源在编译后的文件 %%43^43B^43B32F4B%%index.htm.php 中,它无法让include后的votes.php正常工作。


  index.php,index.htm,%%43^43B^43B32F4B%%index.htm.php这三个文件复杂微妙的关系,我实在是理不清楚,头大啊。

  请问谁有办法解决?

[ 本帖最后由 hetty 于 2007-5-21 13:58 编辑 ]