If Only I Knew That!

Webby things that could save you time

Archive for the ‘Codeigniter’ Category

Codeigniter 2.0 configurable profiler + some jQuery magic to show/hide

without comments

The new CI 2.0 Profiler has configurable sections + 2 new additional sections (http_headers and config).

You’ll need to edit application/config/profiler.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Profiler Sections
| -------------------------------------------------------------------------
| This file lets you determine whether or not various sections of Profiler
| data are displayed when the Profiler is enabled.
| Please see the user guide for info:
|
|	http://codeigniter.com/user_guide/general/profiling.html
|
*/

$config['benchmarks'] 		= TRUE;
$config['get'] 				= TRUE;
$config['memory_usage'] 	= TRUE;
$config['post'] 			= TRUE;
$config['uri_string']		= TRUE;
$config['controller_info']	= TRUE;
$config['queries'] 			= TRUE;
$config['http_headers'] 	= TRUE;
$config['config'] 			= TRUE;

/* End of file profiler.php */
/* Location: ./application/config/profiler.php */

I previously used a modified version of MY_Profiler from dragffy.com. I modified it to add a button to the top of the page that would show or hide the profiler when needed and could also hide the profiler button totally.

Click to continue reading “Codeigniter 2.0 configurable profiler + some jQuery magic to show/hide”

Written by daveganley

May 4th, 2010 at 1:22 pm

Posted in Codeigniter,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
{
}

Written by daveganley

April 13th, 2010 at 10:58 am

Posted in Codeigniter

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

without comments

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 ,

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 one comment

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 , ,

Codeigniter URI routing to give impression of directories

with one comment

I recently had to create a codeigniter site with three main sections and two of the sections needed to appear in directories in the URL’s

  • The main site
  • Backend user dashboard
  • Backend user admin

Click to continue reading “Codeigniter URI routing to give impression of directories”

Written by daveganley

April 14th, 2009 at 10:49 am

Posted in Codeigniter

Tagged with ,

Setting up Codeigniter

with 6 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