Setting a layout view and variables for layout in before()

+1 vote
111 views
asked Aug 23, 2016 in Kohana by Haradzieniec
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->? Are there any other improvements of this code so it looks really good?

1 Answer

0 votes
answered Aug 23, 2016 by Cole
You need to extend your controller template like this below.

class Controller_Main extends Controller_Template {
   //This it the main html container i suggest use html5boilerplaite
   public function $_template = 'layout'; 

   public function action_index() {
      $data = array();
      $this->template->content = View::factory('frontend/home',$data);
   }
}

class Controller_Profile extends Controller_Main{

   public function action_index() {
      $data = array();
      $this->template->content = View::factory('frontend/profile',$data);
   }
}

Related questions

0 votes
1 answer 438 views
asked Aug 23, 2016 in Kohana by Justin
0 votes
1 answer 365 views
asked Aug 23, 2016 in Kohana by James
0 votes
1 answer 247 views
0 votes
1 answer 308 views
0 votes
1 answer 17 views
0 votes
0 answers 171 views
...