Nasrul Hazim Bin Mohamad

Kohana – Tips on Setting up Routes

Jun
04

Always set the default Route the last one, else specific Route will be overwritten

Set specific Route for a particular task

// specific Route for a particular task 
Route::set('doSomething', 'doSomething(/<controller>(/<action>(/<id>)))')
    ->defaults(
		array(
			'directory'  => 'doSomething',
			'controller' => 'page',
			'action'     => 'index',
		)
	);
	
// set default at the last position, else other routes will not work
Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(
		array(
			'directory'  => '',
			'controller' => 'page',
			'action'     => 'index',
		)
	);

Kohana – Routing Configuration( htaccess )

Mar
09

In order to enable Route to fully functional in Kohana 3.3, we need a .htaccess.

Insert the following in .htaccess(create if not exist) to be under Kohana directory.

I save it under /apps/app1(See my post here for my application structure).


# Turn on URL rewriting
RewriteEngine On

# 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.* index.php/$0 [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,L]

Reference: Stack OverFlow

Kohana – Setting up for multiple applications

Mar
06

Make sure to download Kohana first

The structure:

|-apps
|—– app1
|—– -> index.php
|——— 1.0
|——— -> bootstrap.php
|——— 1.1
|——— 1.2
|—– app2
|—– -> index.php
|——— 1.0
|——— -> bootstrap.php
|
|-kohana
|—– version
|——– 3.2.0
|——– 3.3.0

  1. Copy index.php into app/app_1 folder
  2. Copy index.php into app/app_1 folder
  3. Set the following in index.php:
    • Kohana Version -> $kohana_version (new variable)
    • Application Version -> $app_version (new variable)
    • Application Path -> $application
    • Module Path -> $modules
    • System Path -> $system
  4. Set Cookie::$salt = md5('some string here'); in bootstrap.php
  5. Test http://localhost/apps/app1

Reference: Sharing Kohana