Kohana 3.2 tutorial : 2 – Setting up and basic Redirect controller

1. Edit bootstrap.php under “application”:

——————————

date_default_timezone_set('America/Los_Angeles');
Kohana::init(array(
        'base_url'   => '/',
        'index_file' => '',
));

——————–

2. Change the default route to a redirect controller (so we can deal with redirections for misplaced content/old content):

Route::set('default', '(<request>)',
	array(
		'request' => '(.*)',
	))
	->defaults(array(
		'controller' => 'redirect',
		'action'     => 'index',
	));

3.Create the redirect controller

/modules/redirect/classes/controller/redirect.php

<?php
 defined('SYSPATH') or die('No direct script access.');
/**
 * Handles all the redirecions that may happen
 *
 * @package      Redirect
 * @category     SEO
 * @author       Mauricio Otta
 * @license      Confidential. Internal use only.
 */
class Controller_Redirect extends Controller {

	static public function action_index() {
		echo "Controller_Redirect::action_index();<br />";
		echo Request::current()->param('request');
	}

}

4. Test it.

You should see something like this:

“Controller_Redirect::action_index();”

test with different URLs.

Notice the controller does not handle the Query String part ( http://php.net/parse_url )

 

 

TO-DO: Add query string handling

 

 

Bookmark the permalink.

Leave a Reply