Kohana: Buffering output on view and rendering it before in the source code

Sometimes you need to hack the order the source code is going to be rendered in a view: – You want an extra piece of CSS that only aplies to that view, so you think it's not worth creating a single CSS file and including in your mashed file –… Continue reading

Kohana 3: Default Template [step 3]

Create the view for the default template: /modules/common/views/template/default/default.php   <!DOCTYPE html> <head> <title>Default template</title> </head> <body> <?php echo $content; ?> </body> </html>      

Kohana 3.1.x: Common controller [step 2]

Define parent controller:     <?php defined(‘SYSPATH’) or die(‘No direct script access.’); class Controller_Common_Content extends Controller_Template { public $template                = ”; public $template_name           = ‘default’; public $layout                  = ‘default’; public $save_auto_render        = null; public $content                 = ‘{Do something to generate content}’; public function __construct(Request $request, Response $response) { parent::__construct($request, $response);… Continue reading

Kohana 3.2.x: Master Template Controller [step 1]

Let's create a content module that will handle both static and dynamic content: First enable the module: modules/application/bootstrap.php Kohana::modules(array( . . 'content' => MODPATH . 'content', // Content module . . ));   Second, create the master template controller: modules/content/classes/controller/base/template.php template_name = Kohana::$config->load('content.template.name'); $this->template = 'template/'.$this->template_name.'/index'; parent::before(); if ($this->auto_render) {… Continue reading

Great way to integrate SwiftMailer and Kohana 3

Just found this post: http://www.flynsarmy.com/2010/06/integrating-swift-mailer-into-kohana-3/ by Flynsarmy showing the simplest way to integrate SwiftMailer and 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… Continue reading

php:// function to clean string for SEO usage

If you need a good function to clean strings to use them as URLs for SEO purposes, here’s a suggestion: function chunk_special_chars($string) { $normalizeChars = array( ‘Š’=>’S’, ‘š’=>’s’, ‘Ð’=>’Dj’,’Ž’=>’Z’, ‘ž’=>’z’, ‘À’=>’A’, ‘Á’=>’A’, ‘Â’=>’A’, ‘Ã’=>’A’, ‘Ä’=>’A’, ‘Å’=>’A’, ‘Æ’=>’A’, ‘Ç’=>’C’, ‘È’=>’E’, ‘É’=>’E’, ‘Ê’=>’E’, ‘Ë’=>’E’, ‘Ì’=>’I’, ‘Í’=>’I’, ‘Î’=>’I’, ‘Ï’=>’I’, ‘Ñ’=>’N’, ‘Ò’=>’O’, ‘Ó’=>’O’, ‘Ô’=>’O’, ‘Õ’=>’O’,… Continue reading

Great way to parse HTML content using PHP

Today I started improving a newsletter system in the company I work for. One of the things I wanted to change is to have images embedded in the email message. The website uses CodeIgniter (http://www.codeigniter.com); for email handling I chose Swift mailer (http://swiftmailer.org/). Then for HTML parsing to replace all… Continue reading