<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>#! &#187; CodeIgniter</title>
	<atom:link href="http://hash-bang.net/tag/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://hash-bang.net</link>
	<description>The start of all wonderful things</description>
	<lastBuildDate>Mon, 30 Apr 2012 00:28:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Error reporting with CodeIgniter</title>
		<link>http://hash-bang.net/2009/02/error-reporting-with-ci/</link>
		<comments>http://hash-bang.net/2009/02/error-reporting-with-ci/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 02:38:46 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Helpers]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=100</guid>
		<description><![CDATA[While CodeIgniter does come with a reasonable error logging tool its simple nature of just dumping a single line report to a file on a distant server does not seem too pro-active for my tastes. The following helper replaces the default CI error reporting with a new error reporting interface that also emails any errors [...]]]></description>
			<content:encoded><![CDATA[<p>While CodeIgniter does come with a reasonable error logging tool its simple nature of just dumping a single line report to a file on a distant server does not seem too pro-active for my tastes.</p>
<p>The following helper replaces the default CI error reporting with a new error reporting interface that also emails any errors that occur to a nominated developer.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=100&amp;download=err_helper.php">err_helper.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1003"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
</pre></td><td class="code" id="p100code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
* Sensibly report of errors that occur in the system by sending that
* error to the developer
* Author: Matt Carter &lt;m@ttcarter.com&gt;
* Info: http://hash-bang.net/2009/02/error-reporting-with-cierror-reporting-with-ci/
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Where to send the error report. Leave blank for nowhere</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_TO'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'someone@somewhere.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// Literal name of that person</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_TO_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Joe Random'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FROM'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root@freesweetsite.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FROM_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error Daemon'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_METHOD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'SMTP'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Supported: SMTP</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_SENDER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root@somewhere.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// The subject of the mail. Supported tags: [TYPE], [FILE], [LINE], [STRING], [BASENAME]</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_SUBJECT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error detected: [TYPE] @ [BASENAME]:[LINE]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// Other things of interest to include in the email. CSV of supported values: POST, GET, SERVER, GLOBALS, SESSION</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_MAIL_FOOTERS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST,GET,SESSION'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Relative location of PHP mailer to this file</span>
<span style="color: #666666; font-style: italic;">// (Not relative to the working directory because that doesn't specify correctly with fatal errors).</span>
<span style="color: #666666; font-style: italic;">// By default this assumes that the 'phpMailer' folder is located in the same directory as this script.</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERR_PATH_PHPMAILER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'phpMailer/class.phpmailer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> err<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errcontext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$errtable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Fatal'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Parse Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">8</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">16</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Core Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">32</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Core Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">64</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Compile Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">128</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Compile Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">256</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">512</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Warning'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">1024</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">2048</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Strict Notice'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">4096</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Recoverable Error'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">8192</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Deprecated'</span><span style="color: #339933;">,</span>
		<span style="color: #cc66cc;">16384</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'User Deprecated'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;style&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-box {border: 1px solid #4A98AF}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table th {background: #4A98AF; text-align: right; white-space: nowrap}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table td, .err-table th {padding: 5px}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table-stack th {background: #4A98AF; text-align: left}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.err-table-stack th, .err-table-stack td {font-size: 12px}&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/style&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-box<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;table class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-table<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th width=<span style="color: #000099; font-weight: bold;">\&quot;</span>100px<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Type:&lt;/th&gt;&lt;td&gt;{<span style="color: #006699; font-weight: bold;">$errtable</span>[<span style="color: #006699; font-weight: bold;">$errno</span>]}&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Error:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errstr</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;File:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errfile</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Line:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errline</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;Context:&lt;/th&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">$errcontext</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$traces</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'err_shutdown'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Ignore fatal shutdown traces</span>
		<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;table width=<span style="color: #000099; font-weight: bold;">\&quot;</span>100%<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>err-table-stack<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;tr&gt;&lt;th width=<span style="color: #000099; font-weight: bold;">\&quot;</span>50px<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Line&lt;/th&gt;&lt;th&gt;Function&lt;/th&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$traces</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Calculate line number</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// First in trace</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td style=<span style="color: #000099; font-weight: bold;">\&quot;</span>text-align: center<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$errline</span>&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Nth in trace</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td style=<span style="color: #000099; font-weight: bold;">\&quot;</span>text-align: center<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&amp;nbsp;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// Calculate arg stack</span>
			<span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'args'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$arg</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' , '</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argstack'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// Output context</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trace</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'object'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Object error</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$trace['class']}</span>-&gt;<span style="color: #006699; font-weight: bold;">{$trace['function']}</span>(<span style="color: #006699; font-weight: bold;">{$trace['argstack']}</span>)&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Function error</span>
				<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$trace['function']}</span>(<span style="color: #006699; font-weight: bold;">{$trace['argstack']}</span>)&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ERR_MAIL_TO<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> ERR_PATH_PHPMAILER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Cannot find PHP mailer at the relative path '&quot;</span> <span style="color: #339933;">.</span> ERR_PATH_PHPMAILER <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'. Make sure it is located there to send mails&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PhpMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ERR_MAIL_METHOD <span style="color: #339933;">==</span> <span style="color: #0000ff;">'SMTP'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CharSet</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> ERR_MAIL_HOST<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Sender</span> <span style="color: #339933;">=</span> ERR_MAIL_SENDER<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span> <span style="color: #339933;">=</span> ERR_MAIL_FROM<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FromName</span> <span style="color: #339933;">=</span> ERR_MAIL_FROM_NAME<span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span>ERR_MAIL_TO<span style="color: #339933;">,</span> ERR_MAIL_TO_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span>ERR_MAIL_SUBJECT<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'[TYPE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errtable</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errno</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[FILE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[BASENAME]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[LINE]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'[STRING]'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span>
			<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$extras</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\s*,\s*/'</span><span style="color: #339933;">,</span> ERR_MAIL_FOOTERS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Get'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SESSION'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SESSION</span> <span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SERVER'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Server'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GLOBALS'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extras</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GLOBALS</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Globals'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mailobj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Catch fatal errors</span>
<span style="color: #000000; font-weight: bold;">function</span> err_shutdown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #990000;">error_get_last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_CORE_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_COMPILE_ERROR</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		err<span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Fatal error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Array[&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$what</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$what</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _err_dump_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;table class=&quot;err-table-stack&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th colspan=<span style="color: #000099; font-weight: bold;">\&quot;</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Dump of <span style="color: #006699; font-weight: bold;">$title</span> array&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Key&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;<span style="color: #006699; font-weight: bold;">$key</span>&lt;/th&gt;&lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> _err_human<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;div&gt;<span style="color: #006699; font-weight: bold;">$title</span> is empty&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">set_error_handler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">register_shutdown_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err_shutdown'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Installation of the component is similar to any CI helper: drop the file into the application/system/helpers directory and create the associated entry in the application/system/config/autoload.php file like so:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1004"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p100code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then open the above and change the constants at the top of the file to specify where the error messages are sent.</p>
<p>In order to send mail the above component needs the truly excellent <a href="http://phpmailer.codeworxtech.com/index.php?pg=phpmailer">PHPMailer</a> package which can be stashed in the same helpers directory. If you do decide to move it somewhere else change the corresponding constant that specifies the location of the library. A small note of warning though &#8211; the path to the PHP mailer libraries must be relative to the current file NOT the current working directory. This is due to how PHP handles fatal errors which for some reason sets the working directory to &#8216;/&#8217;.</p>
<p>Should there be any interest I may extend the above with other useful features such as RSS, SMS (text messaging) or other non-SMTP methods of emailing.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/02/error-reporting-with-ci/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Talking in tongues &#8211; UTF8 with CodeIgniter</title>
		<link>http://hash-bang.net/2009/02/utf8-with-codeigniter/</link>
		<comments>http://hash-bang.net/2009/02/utf8-with-codeigniter/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 02:55:23 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[UTF8]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=95</guid>
		<description><![CDATA[PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this will be solved with PHP6 and its fancy pants new rendering interface. Until then we have to make do and mend. First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as [...]]]></description>
			<content:encoded><![CDATA[<p>PHP 4 &#038; 5 unfortunately have major problems working with UTF8. Hopefully this <a href="http://www.bionictomato.com/users/Marti-en/154-Preparing-yourself-for-PHP-60.html">will be solved with PHP6</a> and its fancy pants new rendering interface.</p>
<p>Until then we have to make do and mend.</p>
<p>First setup your database to work with UTF8. I won&#8217;t waste time telling you how to do this in MySQL as many people far brighter than I have written <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html">more on the subject</a>.</p>
<p>CodeIgniter comes with UTF8 enabled out of the box so there is little to do configuration wise. Unfortunately pasting a test string such as: 検索 (which I stole from <a href="http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8">this Wikipedia page</a>) into a CI input box will quickly lead to calamity as CI tries to save the string as ASCII.</p>
<p>Simple solution then, save the following helper in your system/application/helpers folder:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=95&amp;download=utf8_helper.php">utf8_helper.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p957"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p95code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
* Rewrite all outgoing text into UTF8 compatible streams
* Author: Matt Carter &lt;m@ttcarter.com&gt;
* Info: http://hash-bang.net/2009/02/utf8-with-codeigniter
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> ob_utf8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ob_utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Re-write all incoming text into UTF8 streams</span>
	<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Then simply add it to your system/application/autoload.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p95code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p958"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p95code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'helper'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The helper will automatically convert incoming POST data into MySQL compatible UTF8 and convert outgoing text into HTML UTF8 streams.</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/02/utf8-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Pretty URLS in CodeIgniter</title>
		<link>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/</link>
		<comments>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 22:49:21 +0000</pubDate>
		<dc:creator>mc</dc:creator>
				<category><![CDATA[HowTo's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://hash-bang.net/?p=81</guid>
		<description><![CDATA[CodeIgniter has to be my favorite framework for PHP. The way it keeps out of your way while working to an MVC standard is something deserving of the highest praise. For reasons passing understanding though the programmers of this excellent system have desided not to provide pretty URL&#8217;s out of the box. Getting infomation on [...]]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter has to be my favorite framework for PHP. The way it keeps out of your way while working to an MVC standard is something deserving of the highest praise.</p>
<p>For reasons passing understanding though the programmers of this excellent system have desided not to provide pretty URL&#8217;s out of the box. Getting infomation on this is a little tricky so here is my take on the situation.</p>
<p>Simply dump the following into a file called &#8216;.htaccess&#8217; (Note the starting Dot) in the root path (thats the one at the very start of your path tree that should contain the &#8216;system&#8217; folder).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://hash-bang.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=81&amp;download=.htaccess">.htaccess</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8111"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p81code11"><pre class="text" style="font-family:monospace;">RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$		- [L]
&nbsp;
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]</pre></td></tr></table></div>

<p>As with most mod_rewrite hacks you will need that enabled on an apache server. Its very rare to find a hosting company that doesn&#8217;t use this setup so you should be fine.</p>
<p>You will also need to change the following variable to a blank value in the system/application/config/config.php file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8112"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p81code12"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'index_page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And you&#8217;re done. From now on your Urls are addressed in the form: http://SITE/CONTROLLER/METHOD/VALUE1/VALUE2 (e.g. http://mysite.com/users/edit/123123)</p>
]]></content:encoded>
			<wfw:commentRss>http://hash-bang.net/2009/01/pretty-urls-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

