Tag Archives: kohana

Kohana HTTPS redirect

To redirect to https in Kohana use the site function in the URL class to create the URL.

eg

$url = URL::site(Route::get('ROUTE_NAME')->uri(), 'https');
Request::Instance()->redirect($url);

To force actions to be loaded using https I do something like this:

The main template controller:

class Controller_Whitelabel extends Controller_Template
{
 
public $ssl_required = false; //controller-wide ssl required
public $ssl_actions = false; //action specific ssl required
 
public function before()
{
 
  parent::before();
 
  $this->sslRedirect();
 
   ..........
}
 
private function sslRedirect()
{
 
   $action_name = Request::instance()->action;
 
   if ( ($this->ssl_required) || (is_array($this->ssl_actions) && in_array($action_name, $this->ssl_actions) ) )
   {
 
      if (Request::$protocol == 'http')
      {
         Request::Instance()->redirect(URL::site(Request::Instance()->uri, 'https'));
      }
 
   }
   else
   {
      if (Request::$protocol == 'https')
      {
         Request::Instance()->redirect(URL::site(Request::Instance()->uri, 'http'));
      }
   }
 
   }

It allows you to set either all actions to require ssl, or only specific ones.

Example Controller where all actions require ssl:

class Controller_Payment extends Controller_Whitelabel {
 
   public $ssl_required = true;
 
   ......
}

Example Controller where only the index & list actions require ssl:

class Controller_Payment extends Controller_Whitelabel {
 
   public $ssl_actions = array('index', 'list');
 
   public function action_index()
   {
   }
 
   public function action_list()
   {
   }
 
   public function action_view()
   {
   }
}

Quotes database – kwotes.co.za

I finished my first personal project using the Kohana Framework. I wanted to see how quickly I could get a very basic site up and running.

I used the ORM plugin (in some areas) for the first time. It works well and is quite straight forward, but I still prefer writing my own SQL.

I build a very simple quotes website with a mobile equivalent. Over all it probably took about a week of doing a few hours each evening. Its lacking in design, but I didn’t want to spend too much time on the css.

Site: www.kwotes.co.za

Mobile Site: m.kwotes.co.za

Kohana Framework

kohana For my latest project I was looking for a much lighter framework than Symfony or CakePHP. All I really wanted was an MVC framework that could handle the routing and templates. I came across Kohana which was originally based on CodeIgnitor (it has since been rebuild from the ground up in PHP5). Version 3.x had just been released so I decided to go for that.

The only problem I have at the moment is lack of decent documentation, but there is an unofficial wiki which covers a fair amount, and an active community of users. But the next best thing is to just browse the API for whatever you need.

So far i’m happy with my decision and the project is going smoothly. In the next few weeks I will post some code snippets and modules that I have written.