tags:

views:

281

answers:

1

Perhaps I'm just missing a basic OOP idea in PHP, but for the life of me, I can't seem to set the "$template" variable dynamically.

If I extend the Template_Controller, I can set the template name like this:

public $template = 'template_file_name';

But I can't set it dynamically like:

public $template = $this->setTemplate();

or

switch($var):
    default:
       public $template = 'filename';
       break;
endswitch;

Changing the $template variable using $this->template in the constructor breaks the Template_Controller somehow:

Fatal error: Call to a member function render() on a non-object

I need to set the template filename based on a variable set in the constructor, or perhaps pulled from an external library.

Any ideas how to make this possible?

+6  A: 

this link may have the answer:

http://stii.co.za/php/overriding-default-template-in-kohana-php/

just run your template constructor as this:

public function __construct()
    {
        $this->template = 'foobar';
        parent::__construct();
    }
gpilotino
so simple - thanks. (setting template before the parent constructor)
jmccartie