2012-09-24 44 views
-3

我有PHP代码:Smarty的变量声明错误

$uid = $xUS['id']; // Current user id 
$uname = $xUS['x_username'];   // Current user name 
$ulink = ''; // Current user profile URL (leave blank for none) 
$upic = $xUS['config_forum_avator_head'];    // Current user 
$ismod = 0;     // Is current user a moderator? 
$sig = md5($uid . $uname . $ismod . 's79tvi40k95bs6mw'); 
$ssoParams = '&uid=' . $uid . "&uname=" . 
urlencode($uname) . "&ulink=" .  urlencode($ulink) . "&upic=" . urlencode($upic) 
. "&ismod=" . $ismod . "&sig=" . $sig;</i> 

我Smarty的模板文件:

<iframe width='550' height='500' src='http://chatroll.com/embed/chat/pibux-chatroom?id=tgybumotNmY&platform=php{$ssoParams}&w=$0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>

在这方面,{$ssoParams}变量返回一个空值。为什么?请帮忙。

回答

0

读Smarty的文档,例如:http://www.smarty.net/docsv2/en/language.variables.tpl#language.assigned.variables

您需要分配一个变量,如:

$smarty = new Smarty(); 

$smarty->assign('ssoParams', $ssoParams); // assign(smarty var, PHP var); $smarty->display('template_file.tpl');

当然,你需要包括Smarty的文件,定义模板等。

查看基本工作示例e 2.9。这里: http://www.smarty.net/docsv2/en/installing.smarty.basic.tpl#id2778275

+0

我试过了,但它给出了500内部服务器错误。 – user1693893

+0

奇怪。检查你的路径是否正确。像这里:require_once(SMARTY_DIR。'Smarty.class.php');或使用: require_once('path/to/smarty/Smarty.class.php');然后也为template_dir,compile_dir等,并使用或取消注释此行,以便您应该接收调试窗口。 ($ smarty-> debugging = true;) 还要确保你调用了正确的模板文件。在这一行中使用您的模板文件的名称:$ smarty-> display('template_file.tpl');还要尝试对CHMOD templates_c目录写入权限。 755,777或类似的东西。 – StudioArena