Can a View in Kohana access the parent variables of the View?

This applies to Kohana 2.3.2

I recently started making my views more dynamic. Using the default template template as a base, I now do in the controller

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

      

Then, in the middle of mine template.php

, I

<?php echo $innerView; ?>

      

Discard the article submission "guts" between my header and footer. This works great, except that all the vars I have defined for $this->template

are not available to the new view. I know what I could do

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

      

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

Whether there is a?

0


a source to share


2 answers


The set_global () method sets the variable to be global for all views. This is not what you think when you hear "Global" in PHP for you to get it right, this is exactly what you should use when you want to make a variable available to multiple views.



+4


a source


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

I need this because I am using the page title in a normal template (for <title></title>

) as well as <h2></h2>

pages.



It's as easy as it is

$this->template->innerView = new View('article');
$this->template->set_global('title', 'My Title');

      

-1


a source







All Articles