Creating a content controller using Kohana v3.0

These are the things I needed to change on .httacess to have kohana default files working before creating my first controller:

 # Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /kohana/

# Protect hidden files from being viewed
<Files .*>
 Order Deny,Allow
 Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)b - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

My Kohana v3 installation is not inside a folder, so I’m changing “/kohana/” to “/“.

I want to use my Content controller to show content for the front page and any other content pages read from the database, so I am doing the following changes to my /application/bootstrap file:

Route::set('default', '(<controller>(/<action>(/<id>)))')
 ->defaults(array(
 'controller' => 'content',
 'action'     => 'index',
 ));

Create the Content controller file /application/classes/controller/content.php

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Content extends Controller {

 public function action_index()
 {
 $this->request->response = 'This is the content controller!';
 }

 public function action_view()
 {
 $this->request->response = 'This is the content controller [view action]!';
 }

} // End Welcome
Tagged , , , . Bookmark the permalink.

Leave a Reply