Guide to CodeIgniter databases

Why are there no, in-depth tutorials covering databases in CodeIgniter?

I?m talking the full nine miles, including Models, ActiveQuery, Configuration, Security, seriously, the full nine miles. Yes the CodeIgniter user guide is spectacular, yes, most people know how to do this stuff anyway, but, I did what I could. I would like to introduce you to?

The CodeIgniter Guide To Databases.

http://jamierumbelow.net/blog/the_guide_to_ci_databases/

Mod_rewrite: RewriteCond

For a plain English translation, go down to the end…

RewriteCond
Syntax: RewriteCond TestString CondPattern

The RewriteCond directive defines a rule condition. Precede a RewriteRule directive with one or more RewriteCond directives. The following rewriting rule is only used if its pattern matches the current state of the URI and if these additional conditions apply too.

TestString is a string which can contains the following expanded constructs in addition to plain text:
– RewriteRule backreferences
– RewriteCond backreferences
– RewriteMap expansions
– Server-Variables

Note that this is a simplified version of what’s at http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond
which goes on for several pages about this in vast detail.

To put it into plain English:
Say you have this (as can be found in a CodeIgniter .htaccess file):
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

What this means is:
IF the incoming Request URI (ie the address requested by the browser) matches “system”
THEN rewrite it so that it uses the index.php file in the root directory.

For explanation of RewriteRule see an earlier post.

Mod_rewrite: RewriteBase

This basically says:
We are in the directory “/abc” but please process all Rewrites as if you were in a root directory (i.e. ignore the directory /abc).

What it does is strip this directory off before processing further rules then add it back on at the end.

From the Apache docs:
The RewriteBase directive explicitly sets the base URL for per-directory rewrites. As you will see below, RewriteRule can be used in per-directory config files (.htaccess). There it will act locally, i.e., the local directory prefix is stripped at this stage of processing and your rewriting rules act only on the remainder. At the end it is automatically added back to the path.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteBase

Getting rid of index.php from your CodeIgniter URLs

Here are the steps you need to follow:
1. Create a .htaccess file to configure the rewrite engine (an example htaccess file follows at the end)

2. Set $config[?index_page?] to an empty string

3. Make sure your apache uses the mod_rewrite module

4. Make sure apache is configured to accept needed .htaccess directives

5. Restart apache and test

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#’system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php

Source: http://codeigniter.com/wiki/mod_rewrite/

RewriteRule

RewriteRule:
Syntax: RewriteRule Pattern Substitution

Here’s an example you could use in a .htaccess file:
RewriteRule ^(.*)$ /index.php/$1 [L]
which says if you have a URL like this:
/wordA/wordB/wordC
then replace it with
/index.php//wordA/wordB/wordC

where the not very user-friendly [L] flag means “stop processing”:
‘last|L’ (last rule)
Stop the rewriting process here and don’t apply any more rewriting rules. This corresponds to the Perl last command or the break command from the C language. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL (‘/’) to a real one, e.g., ‘/e/www/’.

See here for more details:
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Creating Japanese CSV files that Excel can read…

Here’s a test script…

These pages are helpful:
http://uk.php.net/manual/en/ref.mbstring.php
(see Smelly’s comment 26-Apr-2007 06:09)

http://uk.php.net/manual/en/mbstring.ja-basic.php

http://en.wikipedia.org/wiki/Unicode

See also:
http://macdiggs.com/index.php/2007/11/08/japanese-language-cvs-export-for-excel/

http://www.tek-tips.com/viewthread.cfm?qid=1172405&page=1

http://support.microsoft.com/kb/326758