Posted (Updated ) in PHP

Have you ever wanted to generate a resized version of an image just using a HTML image tag and not worrying about entering large chunks of resizing code or storing cached images of various sizes? Today’s tutorial will show you exactly how to do that with Kohana 3. In this tutorial I will teach how to use the URL http://www.mysite.com/sized/image/// to load a dynamically generated, resized image.

The trickiest concept to grasp in this tutorial are the URL segments. Imagine your site was located at http://www.mysite.com and you were browsing to this page http://www.mysite.com/archive/posts/my-post. In this instance, ‘segment 1’ would be archive, segment 2 posts and segment 3 my-post. Segments are split with the / character. In Kohana, URL segments take the following form: controller/method/method_arg_1/method_arg_2/etc…

Read More »

Posted (Updated ) in PHP

As with any project involving generation of .xlsx spreadsheets there’s only really one way to go – PHPExcel. This amazing piece of software boasts a large feature set – allowing quick and (relative) painless generation of XLS, XLSX, PDF, and CSV to name a few as well as importing of the same sans PDF. I recently had to integrate PHPExcel into Kohana 3 so I figured I’d take the time to post the how-to and hopefully make your lives that little bit easier. In addition I’ve included a quick and dirty Spreadsheet class to make XLSX generation that bit faster.

Read More »

Posted (Updated ) in PHP

This is quite possibly one of the simplest integrations in Doctrine history (It’s a 1 liner, folks). The following is a short tutorial on how to create a SwiftMailer module for Kohana 3

Create the following files/folders:
/modules/swiftmailer
/modules/swiftmailer/init.php
/modules/swiftmailer/classes

Inside /modules/swiftmailer/classes/ drop the official latest build of Swift Mailer.

Enter the following into init.php.

<?php
	require Kohana::find_file('classes', 'Swift-4.0.6/lib/swift_required');

There. Wasn’t that easy? Remember to enable the module by adding it to your bootstrap.php file!

Read More »

Posted (Updated ) in PHP

In Kohana 2, html::script() and html::stylesheet() accepted an array or string as their first arguments. This allowed you to easily add multiple scripts and styles simultaneously without needing to write several lines of redundant code. Kohana 3 has removed this useful ability so I thought I’d write a very quick extension to add the feature back in. The following script adds HTML::scripts() and HTML::styles() (As Kohana 3 slightly renamed their functions to HTML::script() and HTML::style() respectively).

Simply add the following file html.php to your /classes directory:

<?php defined('SYSPATH') or die('No direct script access.');
 
class HTML extends Kohana_HTML {
	public static function scripts(array $scripts, $attributes=array(), $index = FALSE)
	{
		$response = '';
 
		//Data sanitisation
		$index = $index ? TRUE : false;
		if ( !is_array($attributes) ) $attributes = array();
 
		foreach ( $scripts as $script )
			$response .= html::script($script, $attributes, $index);
 
		return $response;
	}
 
	public static function styles(array $styles, $attributes=array(), $index = FALSE)
	{
		$response = '';
 
		//Data sanitisation
		$index = $index ? TRUE : false;
		if ( !is_array($attributes) ) $attributes = array();
 
		foreach ( $styles as $style )
			$response .= html::style($style, $attributes, $index);
 
		return $response;
	}
}

Download: html.php

Usage:

<?php
echo HTML::styles(array(
	'assets/css/reset',
	'assets/css/styles',
);
echo HTML::scripts(array(
	'assets/js/jquery',
	'assets/js/jquery.ui.all',
);
?>

Note: Both functions accept the latter 2 parameters available in Kohana 3 HTML::scripts() and HTML::styles(). If used, these arguments will be applied to every element in the first arguments array.

Read More »

Posted (Updated ) in Database, PHP

It’s probably become apparent by now that I like Doctrine. It’s quick, it’s easy and it works with everything. So here’s a Doctrine driver for the Kohana Auth module, allowing you to use Doctrine instead of Kohanas integrated ORM.

Download: Kohana Auth Doctrine Driver 1.03 here

Installation instructions:
Unzip the module to your /modules folder.
Enable the module by adding

'auth_doctrine' => MODPATH.'auth_doctrine',  // Doctrine driver for Auth module

to the modules array in the following file:
Kohana 3:/bootstrap.php
Kohana 2: /config/config.php

UPDATE Jul 15 2010: Fixed incorrect user login bug. Please redownload
UPDATE Dec 22 2010: Fixed ‘remember’ session bug.
UPDATE Jan 3 2011: Fixed bug if calling Auth::instance()->logged_in(‘role_name’). Thanks to freenode #doctrine user SirFunk for this one – good catch!
Update Feb 21 2011: New module at a new home! See here for details

Read More »

Posted (Updated ) in Database, PHP

Update Feb 21 2011: New module at a new home! See here for details

Upon the release of Kohana 3, one of the first things I wanted to do was install Doctrine. The following is a short tutorial on how to do; and keeping with Kohanas modular style, it will be placed in its own reusable module. Time to begin.

Create the following files/folder:
/modules/doctrine
/modules/doctrine/init.php
/modules/doctrine/classes
/modules/doctrine/classes/doctrine

Inside /modules/doctrine/classes/doctrine drop the official latest build (see here) of Doctrine such that Doctrines CHANGELOG, COPYRIGHT etc files etc are inside.

Enter the following into init.php. Note – this may not be the optimal bootstrap file – feel free to tweak to your hearts content.

Read More »

Posted (Updated ) in Uncategorized

Here’s another little gem for you HTML5 fans out there – link prefetching. Adding the following into a HTML meta or link tag will result in the target being loaded in the background after your current page.

<link rel="prefetch" href="/images/big.jpeg">
or
<link rel="next" href="2.html">
or
<meta http-equiv="Link" content="/images/big.jpeg" rel=prefetch">

Both ‘prefetch’ and ‘next’ are accepted.

Here are a few advantages of using this method:

  • It’s HTML compliant
  • It’ll dramatically speed up the resulting page/file if successfully prefetched
  • It doesn’t slow current page load
  • No same-origin restriction – any domain is accepted

There are several limitations to this method that should be noted:

  • Firefox only (for now)
  • Only HTTP protocol is accepted
  • No URLs with querystrings accepted

To learn more about link prefetching check out the Link Prefetching FAQ at Mozilla Developer Center

Read More »

Posted (Updated ) in Database, PHP

When it comes to online shopping carts, LemonStand is the hot new thing. Still in beta, this piece of software boasts a surprisingly large feature set and high level of customization options usually only seen in much larger CMS’s. The one narking issue I’ve had with it so far is its choice of URL separator – preferring underscores over dashes. After speaking to the very polite and friendly developer behind LemonStand, a solution was quickly devised.

To convert the default URL separator in LemonStand from underscores to dashes simply add the following line of code to your config/config.php file.

$CONFIG['URL_SEPARATOR'] = '-';

Update 3 Jun 2010: I’ve received word from the author behind LemonStand that he’ll be publishing an update later today changing the default URL separator from underscores to dashes. The change will not affect any existing installations and only apply to new installations. For developers wishing to change the default separator on new pages on existing installations, the fix above still applies. This is great news that I’m sure many developers out there will be pleased with.

Read More »

Posted (Updated ) in Uncategorized

Let me preface this post by stating that I have the design talent of the average developer – that is to say: none. So when I decided to start learning about CSS3 @font-face I thought I was going to be in for a night of pain; boy was I right.

The post headings on site are rendered in the Museo font using Cufon. Cufon is an amazing piece of JavaScript that allows you to embed fonts into webpages making them visible in all browsers. It works as advertised, however it has a habit of causing pains for visitors on slower connections. For this site, the cufon script is 17.8KB and Museo font package is an added 190.4KB – a hefty download. At this point, the developer in me would declare the benefits not to be worth the drawbacks and scrap it all together. Luckily for all of you though, I’m constantly surrounded by talented designers, namely That Stevens Guy and begrudgingly blindly follow what they tell me to do in that department. So cufon has stayed. Is there a better solution though? Meet @font-face.

Read More »

Posted (Updated ) in Javascript

Recently while randomly browsing I came across a method of displaying multiple tabs using only HTML and CSS (see here for the explanation or here for an amazing demo). This presented an interesting concept – tabs with no JavaScript. There are quite a few drawbacks but in the right conditions this could be a good addition to your site.

Read More »