Template Site : Basic Page Controller

Now that we have set up a template and extended the Kohana template controller so that we can customize how our web site responds, it is now time to create an actual page controller so that we can start serving web pages.

Our page controller will be called page.php and should be created in the following directory

  /home/kerkness/kohana/application/classes/controller/page.php

Click here for the source file

Here is our page controller. It contains two actions, one for loading a home page and another for loading a contact page.

  <?php defined('SYSPATH') or die('No direct script access.');
  
  class Controller_Page extends Controller_Demo {
  
  	public function action_home()
  	{
  		$this->template->title = __('Welcome To Acme Widgets');
  		
  		$this->template->content = View::factory('page/home' );
  	}
  	
  	public function action_contact()
  	{
  		$this->template->title = __('Contact Information for Acme Widgets');
  		
  		$this->template->content = View::factory('page/contact' );
  	}
  	
  } 

Now we have to create view files for our two pages. The files will be call home.php and contact.php and should be created in the following location.

  /home/kerkness/kohana/application/views/page/home.php
  /home/kerkness/kohana/application/views/page/contact.php

Click here for the source files

Here are two view files you can use. At the moment these are very basic but could be customized to any extent.

home.php

  <h1>Welcome to our homepage.</h1>
  
  <p>We love our new Kohana web site</p>

contact.php

  <h1>How to contact us.</h1>
  
  <p>We don't like to be contacted so don't bother.</p>
template-site/basic_page_controller.txt · Last modified: 2009/10/15 01:30 by kerkness