Question

This applies to Kohana 2.3.2

I've recently started making my Views more dynamic. Using the default template view as a base, now I am doing in the controller

$this->template->innerView = new View('article');

Then, in the middle of my template.php, I have

<?php echo $innerView; ?>

To echo the 'guts' of the article view between my header and footer. This works fine, except all the vars I defined to$this->template are inaccessible from the new view. I know I could probably do

$this->template->innerView->title = 'My Title';

But if there was a way to make child Views inherit their parent's variables, that would be great.

Is there?

Was it helpful?

Solution

The set_global() method only sets the variable to be global across all views. It's not what you think when you hear "Global" in PHP so you got it right, this is exactly what you should use when you want to make a variable available across multiple views.

OTHER TIPS

http://docs.kohanaphp.com/core/view#set_global

I needed this because I use the page title in the normal template (for within <title></title>) and also as the <h2></h2> of the page.

It's as simple as this

$this->template->innerView = new View('article');
$this->template->set_global('title', 'My Title');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top