phpcode-separation

PHP Passing variables to included file


I have a very simple template class that allows me to set some values and then include a template file. The class stores the variables, and the template file can access using $this->variable.

So my question is how should I go about doing this? Or perhaps it'd be better to just assign some variables and then include the template file - that way they don't need to be passed around?


Solution

  • If you call `extract' like this:

    extract( $this -> variables );
    

    on top on your template code, you will be able to refer to $this -> variables[foo] as $foo.