views:

50

answers:

4
class Theme
{
    function __construct()
    {

    }

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

on index.php

<?php

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

on my site/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');
?>

somehow it needs to $theme = new Theme; again on site/index.php

is there another way to make it work? maybe my class design is not good or algorithm is failing.

edit* more information ok so what im trying to do is to load header view footer view.

Thanks Adam Ramadhan

+1  A: 

The object "$theme" doesn't persist throughout several files, so when "site/index.php" is requested, your object from "index.php" is gone ...

Either that or I got your question completely wrong :)

Select0r
+2  A: 

We don't know the relationship between your two .php files so it would be difficult to answer.

If you define $theme as new theme, scoping rules still apply: you definition/instanciation is only valid on its scope. You won't have a global theme object. Independtly from any class/object design.

Cedric H.
A: 

Try to make load function public:

class Theme
{
    function __construct()
    {

    }

    public static function load( $folder, $file )
    {
        $theme_path = ROOTPATH . '/theme/' . $folder . '/' . $file . '.php';
        require_once($theme_path);
        return TRUE;
    }
}
Alexander.Plutov
PHP class members (both fields and methods) are public by default.
kevinmajor1
A: 
class Theme
{
    function __construct()
    {

    }

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

on index.php

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

on my site/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');
?>

this done the trick for the while, thanks guys.

Adam Ramadhan