一个php技术问题,麻烦指点下
我不是个合格的程序员,没有学php,不过凭着点ruby on rails的经验还算能看懂和改一些uch的代码。不过现在碰到个问题,可能是变量的作用域的问题,不过按照我翻书和查找的结果,可能是基础知识的某个问题,所以在这求助下:
问题出现在修改个人空间的首页渲染模板的地方,默认的,space_index是所有个人空间的首页,但是现在我需要做一个选择,当式样为默认,也就是css和主框架相同时,我需要改成渲染space_default,而式样为自选时,才为space_index。原因是我改动了主框架。
代码如下:
source/space_index.php
$template_name = '';
if($theme == 'uchomedefault') {
global $template_name;
$space['theme'] = $space['css'] = '';
$template_name = 'space_default';
} elseif($theme) {
$cssfile = S_ROOT.'./theme/'.$theme.'/style.css';
$template_name = 'space_index';
if(file_exists($cssfile)) {
$space['theme'] = $theme;
$space['css'] = '';
}
} else {
if(!$space['self'] && $_SGLOBAL['member']['nocss']) {
$space['theme'] = $space['css'] = '';
}
}
include_once template($template_name);
这里有一个问题,即便我按照书上声明$template_name为global也不行,为什么呢?即便if语句算作一个代码块,里面的变量为私有,这个赋值语句该如何写呢?
每次template渲染得到的都是“”。错误原因应该是变量的作用域和变量赋值,我该如何修改呢?
麻烦懂的朋友指点下。谢谢
[ 本帖最后由 星203 于 2008-7-2 10:42 编辑 ]