If Only I Knew That!

Webby things that could save you time

Quick and easy block commenting for testing

with 4 comments

To save time commenting and uncommenting during development we use a little trick with the comment block that allows us to add or remove a single character ‘\’ to comment/uncomment a block.

Uncommented

/* */
Block of code
/* */

Commented

/* *\/
Block of code
/* */

Quick and simple time saver

Written by daveganley

April 21st, 2010 at 4:25 pm

Posted in PHP

CI-1.7.2 to CI-2.0 Model compatibility tweak

without comments

Spotted this in Ben Edmunds Ion Auth model, great way of making your models CI-1.7.2+ compatible.

//  CI 2.0 Compatibility
if(!class_exists('CI_Model')) { class CI_Model extends Model {} }

class MY_Model extends CI_Model
{
}

UPDATED:
Another way

// Let's add support for both Codeigniter 1.7 and 2.0
// Thanks to Dan Horrigan (http://dhorrigan.com/).
if (CI_VERSION >= 2)
{
  require_once(BASEPATH . 'core/CI_Model' . EXT);
  
  // Create an empty class so that we can extend Model while providing support for both CI 1.7 and 2.0
  class Model extends CI_Model {}
}
else
{
  require_once(BASEPATH . 'libraries/Model' . EXT);
}

// Then extend the CI 1.7 Model as usual

Written by daveganley

April 13th, 2010 at 10:58 am

Posted in Codeigniter

Setting up Codeigniter with dynamic configuration variables – fit for development teams

with one comment

When working in a team it is necessary to create dynamic configuration variables for Codeigniter so you can easily share code on development, staging and live servers.

For example, in the team, each developer connects to a common development server (called “localhost”). There is a password protected remote staging server so clients can access it in parallel to the live site (eg. http://client.domain.com). The live site also has a public domain (eg. www.domain.com).  So we need 3 sets of “base_url” and “database” settings.

Click to continue reading “Setting up Codeigniter with dynamic configuration variables – fit for development teams”

Written by ronny

September 29th, 2009 at 4:25 pm

Posted in Codeigniter

Tagged with ,

Reduce Bandwidth with mod_deflate and .htaccess

with one comment

There is something called mod_deflate for Apache 2.x that helps to do auto compression. This is particularly helpful in reducing bandwidth of those nasty jquery plugins.

Step 1:

Add this to the config file (eg. httpd.conf) and then reload Apache

LoadModule deflate_module modules/mod_deflate.so

Step 2:

Then add this to the .htaccess file (to automatically compress javascript, css, html and xml):

<Module mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>

Written by ronny

September 29th, 2009 at 4:24 pm

Posted in Apache

Tagged with ,

New site built on Codeigniter

without comments

Healthy Life Awards

Not really a webby thing that could save you time but yesterday we finished a 2 phase build.

Phase 1: A user backend as such, consisting of a 7 part entry form including ajax image cropping, lots of custom validation and conditional form elements.

Phase 2: The frontend, uses Infinite scroll to create a single page of user profiles, there is also a ajax rating system.

Codeigniter allowed use to build the site in 6 weeks, with 3 solid weeks dev on the forms. All the JS is jQuery based.

Check it out for yourself healthy life awards

Written by daveganley

August 7th, 2009 at 9:13 am

Posted in Codeigniter

Tagged with ,

An improved .htaccess file to remove index.php in CI

with 3 comments

A quick update of the .htaccess to remove the index.php, while still protecting the application folder.

The previous method I used meant having to add every real file or directory to the .htaccess to allow them to be accessed. The updated way checks if the requested file/directory exists and if need rewrites to the index.php.

If you need to protect more directories separate them with | i.e. application|modules

RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Written by daveganley

August 7th, 2009 at 8:43 am

Posted in Codeigniter

Tagged with , ,

Adding Meta data to a codeigniter view from a controller

with 2 comments

To make adding meta data to a view easier, in the controller add to your method

$meta = array (
			'meta_title' 			=> 'title here',
			'meta_keywords' 		=> 'keywords here',
			'meta_description' 		=> 'description here',
			'meta_robots' 			=> 'all',
			'extra_headers' 		=> '
				    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
				    <script type="text/javascript">
				     	<!--
				     	google.load("jquery", "1.3.2");
				     	-->
				    </script>'
		);

		$data = array();
		// add any data

		// merge meta and data
		$data = array_merge($data,$meta);

		// load view with data
		$this->load->view('pages/home', $data);

The extra header allows adding additional JS and CSS to the specific view

In your view add the following head code

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php if(isset($meta_title)) echo $meta_title; ?></title>
    <meta name="keywords" content="<?php if(isset($meta_keywords)) echo $meta_keywords; ?>" />
    <meta name="description" content="<?php if(isset($meta_description)) echo $meta_description; ?>" />
    <meta name="robots" content="<?php if(isset($meta_robots)) echo $meta_robots; ?>" />
   
    <?php if(isset($extra_headers)) echo $extra_headers; ?>
</head>

Written by daveganley

July 26th, 2009 at 3:00 pm

Posted in Codeigniter

Tagged with

Switching codeigniter profiler on/off globally

with 2 comments

In my post regarding setting up codeigniter, I created a debug setting in /application/config/application.php

/*
|--------------------------------------------------------------------------
| Debug
|--------------------------------------------------------------------------
*/
$config['debug']	= TRUE;

in the constructor of every controller I add

$this->output->enable_profiler($this->config->item('debug'));

Now all I have to do is change the value in the application config to enable/disable profiling globally

Written by daveganley

April 15th, 2009 at 2:06 pm

Posted in Codeigniter

Tagged with , ,

Setting up Codeigniter

with 11 comments

After setting up several codeigniter based sites with dev/staging/production environments, I thought I’d write up the steps I undertake.

A overview of the steps are:

  1. Download CI and upload to hosting environment
  2. Rename ‘system’ directory
  3. Move ‘application’ directory to public accessible directory
  4. Upload and modify index.php
  5. Add .htaccess to remove index.php from URL’s
  6. Modify ‘config.php’ for domain and remove of index.php form URL’s
  7. Add ‘application.php’ specific config file
  8. Modify ‘database.php’ config for dev/staging/production
  9. Modify the autoload config for regularly used libraries, helpers and application config file

Click to continue reading “Setting up Codeigniter”

Written by daveganley

April 13th, 2009 at 1:00 pm

Posted in Codeigniter

Tagged with , , , ,

Powered by CDN Rewrites

WordPress Loves AJAX