class Theme
{
function __construct()
{
}
function load( $folder, $file )
{
$theme_path = ROOTPATH . '/theme/' . $folder . '/' . $file . '.php';
require_once($theme_path);
return TRUE;
}
}在index.php上
<?php
require class.theme.php
$theme = new Theme;
$theme->load('site','index');
?>在我的网站/index.php上
<?php
// to work i need another $theme = new theme; why can i do this ? can i make
it make it work twice or more inside the function load ?
$theme->load('site','header');
$theme->load('site','footer');
?>不知何故,它需要$theme =新主题;再次在站点/index.php上
有没有其他方法可以让它工作呢?也许我的类设计不好,或者算法失败了。
编辑*更多信息,好的,所以我想做的是加载页眉视图和页脚视图。
发布于 2010-08-18 22:30:05
class Theme
{
function __construct()
{
}
function load( $folder, $file )
{
$theme_path = ROOTPATH . '/theme/' . $folder . '/' . $file . '.php';
return $theme_path;
}
}在index.php上
<?php
require class.theme.php
$theme = new Theme;
require_once $theme->load('site','index');
?>在我的网站/index.php上
<?php
// to work i need another $theme = new theme; why can i do this ? can i make
it make it work twice or more inside the function load ?
require_once $theme->load('site','header');
require_once $theme->load('site','footer');
?>这就暂时解决了问题,谢谢大家。
发布于 2010-08-17 20:28:25
我们不知道您的两个.php文件之间的关系,因此很难回答。
如果您将$theme定义为新主题,作用域规则仍然适用:您的定义/实例化仅在其作用域上有效。你不会有一个全局主题对象。独立于任何类/对象设计。
发布于 2010-08-17 20:28:24
对象"$theme“不会在多个文件中持续存在,所以当"site/index.php”被请求时,"index.php“中的对象就消失了……
或者我把你的问题完全弄错了:)
https://stackoverflow.com/questions/3502337
复制相似问题