首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php新手类

php新手类
EN

Stack Overflow用户
提问于 2010-08-17 20:24:58
回答 4查看 92关注 0票数 1
代码语言:javascript
复制
class Theme
{
    function __construct()
    {

    }

    function load( $folder, $file )
    {
        $theme_path = ROOTPATH . '/theme/' . $folder . '/' . $file . '.php';
        require_once($theme_path);
        return TRUE;
    }
}

在index.php上

代码语言:javascript
复制
<?php

require class.theme.php
$theme = new Theme;
$theme->load('site','index');
?>

在我的网站/index.php上

代码语言:javascript
复制
<?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上

有没有其他方法可以让它工作呢?也许我的类设计不好,或者算法失败了。

编辑*更多信息,好的,所以我想做的是加载页眉视图和页脚视图。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-08-18 22:30:05

代码语言:javascript
复制
class Theme
{
    function __construct()
    {

    }

    function load( $folder, $file )
    {
        $theme_path = ROOTPATH . '/theme/' . $folder . '/' . $file . '.php';
        return $theme_path;
    }
}

在index.php上

代码语言:javascript
复制
<?php
require class.theme.php
$theme = new Theme;
require_once $theme->load('site','index');
?>

在我的网站/index.php上

代码语言:javascript
复制
<?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');
?>

这就暂时解决了问题,谢谢大家。

票数 0
EN

Stack Overflow用户

发布于 2010-08-17 20:28:25

我们不知道您的两个.php文件之间的关系,因此很难回答。

如果您将$theme定义为新主题,作用域规则仍然适用:您的定义/实例化仅在其作用域上有效。你不会有一个全局主题对象。独立于任何类/对象设计。

票数 2
EN

Stack Overflow用户

发布于 2010-08-17 20:28:24

对象"$theme“不会在多个文件中持续存在,所以当"site/index.php”被请求时,"index.php“中的对象就消失了……

或者我把你的问题完全弄错了:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3502337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档