Hi there programmers!
I'm building a little MVC system (learning) and I have some problems with showing variables in my view files.
This is from my View class:
private $vars = array();
    public function __set($key, $value)
    {
        $this->vars[$key] = $value;
    }
    public function __get($key)
    {
        return $this->vars[$key];
    }
    public function __toString()
    {
        return $this->vars[$key];
    }
    public function show($file)
    {
        global $router;
        $folder = strtolower($router->current_controller);
        $path = VIEWPATH.$folder.'/'.$file.'.phtml';
        if ( ! file_exists($path))
        {
            die("Template: $file, not found");
        }
        include ($path);
    }
And here is from my controller:
$test = new View();
$test->name = 'karl';
$test->show('name_view'); 
And the view file (name_view)
echo $name // doesn't work
echo $this->name // Works
What am I doing wrong? Perhaps I haft to make something global?
THX / Tobias
EDIT: I just extracted the vars array in the view class right before I include the view file and then it worked.. Thank you for all help.