Kohana newbie: setting a layout view and variables for layout in before() The same view (a layout) used for all pages in Kohana3.3 project. That's why it could be placed in before() method instead of every action. Right?

Is there any better way to optimize the code below so you shouldn't use so many $this-&gt;? Are there any other improvements of this code so it looks really good?

public function before()
{   //shows layout for all pages
    $this-&gt;view = View::factory('layout');
    $this-&gt;view-&gt;left_column='pass this string to layout';
}

public function action_index()
{   //index section on the page
    $this-&gt;view-&gt;content = View::factory('index');
    $this-&gt;view-&gt;content-&gt;text = 'some index text';
    $this-&gt;response-&gt;body($this-&gt;view);
}

public function action_about()
{
    //about section on the page
    $this-&gt;view-&gt;content = View::factory('about');
    $this-&gt;view-&gt;content-&gt;text = 'some about text';
    $this-&gt;response-&gt;body($this-&gt;view);
}
Your code is violating the "Don't Repeat Yourself" (DRY) Principle, which is why it seems like you have "too many" $this-&gt;* lines. As the name implies, your code should not repeat. Usually, in an instance such as this, I would say to use the constructor and inject those values you need; However, I don't know for sure if the class you provided is also a factory, in which case you would use a wrapper method.

//non-factory method
public function __construct( $view, $text ) {
    $this-&gt;view-&gt;content = View::factory( $view );
    $this-&gt;view-&gt;content-&gt;text = $text;
    $this-&gt;response-&gt;body( $this-&gt;view );
}

//no other methods need, simply inject while instantiating

//factory method
public function render( $view, $text ) {
    $this-&gt;view-&gt;content = View::factory( $view );
    $this-&gt;view-&gt;content-&gt;text = $text;
    $this-&gt;response-&gt;body( $this-&gt;view );
}

public function action_index() {
    $this-&gt;render( 'index', 'some index text' );
}