Archive for the ‘Codeigniter’ Category
Codeigniter 2.0 configurable profiler + some jQuery magic to show/hide
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”
CI-1.7.2 to CI-2.0 Model compatibility tweak
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
{
}
Setting up Codeigniter with dynamic configuration variables – fit for development teams
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.
New site built on Codeigniter
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
An improved .htaccess file to remove index.php in CI
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]
Adding Meta data to a codeigniter view from a controller
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>
Switching codeigniter profiler on/off globally
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
Codeigniter URI routing to give impression of directories
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”
Setting up Codeigniter
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:
- Download CI and upload to hosting environment
- Rename ‘system’ directory
- Move ‘application’ directory to public accessible directory
- Upload and modify index.php
- Add .htaccess to remove index.php from URL’s
- Modify ‘config.php’ for domain and remove of index.php form URL’s
- Add ‘application.php’ specific config file
- Modify ‘database.php’ config for dev/staging/production
- Modify the autoload config for regularly used libraries, helpers and application config file
