<?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>onemoretake &#187; CodeIgniter</title>
	<atom:link href="http://www.onemoretake.com/category/codeigniter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onemoretake.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 08:28:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CodeIgniter Snippets for Visual Studio</title>
		<link>http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/</link>
		<comments>http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 08:28:37 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs.php]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=336</guid>
		<description><![CDATA[I thought I would share something I have been using for quite a while now and find incredibly useful. They are two snippets for Visual Studio that create the standard file start and file end for php files in the codeigniter framework. If you are not sure what I mean then check out the files [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I would share something I have been using for quite a while now and find incredibly useful. They are two snippets for Visual Studio that create the standard file start and file end for php files in the <a href="http://codeigniter.com">codeigniter framework</a>. If you are not sure what I mean then check out the files that make up the framework &#8211; you will notice that they all tend to start with:</p>

<div class="wp_syntax"><div class="code"><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></pre></div></div>

<p>and end with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* End of file MyFile.php */</span>
<span style="color: #666666; font-style: italic;">/* Location: ./path/to/file/MyFile.php */</span></pre></div></div>

<p>The line at the start of the file is a security measure to stop files being executed outside the framework, whilst the end is just informative but useful anyhow.</p>
<p>I like to do the same thing with all the files I create for my applications but found the typing tedious and because I use the <a href="http://jcxsoftware.com/">VS.php</a> in Visual Studio, I decided to write a couple of snippets to do it for me. </p>
<p>If you are not familiar with snippets in Visual Studio or how to get the following xml to work as a snippet, you can <a href="http://msdn.microsoft.com/en-us/library/ms165392%28VS.80%29.aspx">read all about then on msdn</a>. Anyhow, without further ado, here they are:</p>
<p>filestart.snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CodeSnippets</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CodeSnippet</span> <span style="color: #000066;">Format</span>=<span style="color: #ff0000;">&quot;1.0.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>filestart<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dan Sargeant<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CodeIgniter File start to stop direct script access<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;HelpUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/HelpUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Expansion<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SurroundsWith<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Shortcut<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>filestart<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Shortcut<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Snippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Code</span> <span style="color: #000066;">Language</span>=<span style="color: #ff0000;">&quot;PHP&quot;</span> <span style="color: #000066;">Kind</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">Delimiter</span>=<span style="color: #ff0000;">&quot;$&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');</span>
<span style="color: #339933;">]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Snippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CodeSnippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CodeSnippets<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>fileend.snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CodeSnippets</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CodeSnippet</span> <span style="color: #000066;">Format</span>=<span style="color: #ff0000;">&quot;1.0.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>fileend<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dan Sargeant<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CodeIgniter file ending<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Shortcut<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>fileend<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Shortcut<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Expansion<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SurroundsWith<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SnippetTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Snippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Declarations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Literal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>filename<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ToolTip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Filename<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ToolTip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>myfile.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Literal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Literal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>directory<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ToolTip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Directory<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ToolTip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>models<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Literal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Declarations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Code</span> <span style="color: #000066;">Language</span>=<span style="color: #ff0000;">&quot;PHP&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">/* End of file $filename$*/</span>
<span style="color: #339933;">/* Location: ./application/$directory$/$filename$*/]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Snippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CodeSnippet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CodeSnippets<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>



<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=CodeIgniter+Snippets+for+Visual+Studio+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;t=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;title=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;title=CodeIgniter+Snippets+for+Visual+Studio&amp;summary=I%20thought%20I%20would%20share%20something%20I%20have%20been%20using%20for%20quite%20a%20while%20now%20and%20find%20incredibly%20useful.%20They%20are%20two%20snippets%20for%20Visual%20Studio%20that%20create%20the%20standard%20file%20start%20and%20file%20end%20for%20php%20files%20in%20the%20codeigniter%20framework.%20If%20you%20are%20not%20sure%20what%20I%20mean%20then%20check%20out%20the%20files%20that%20mak&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;title=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;Title=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;title=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;t=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/&amp;title=CodeIgniter+Snippets+for+Visual+Studio" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22CodeIgniter%20Snippets%20for%20Visual%20Studio%22&amp;body=Link: http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20thought%20I%20would%20share%20something%20I%20have%20been%20using%20for%20quite%20a%20while%20now%20and%20find%20incredibly%20useful.%20They%20are%20two%20snippets%20for%20Visual%20Studio%20that%20create%20the%20standard%20file%20start%20and%20file%20end%20for%20php%20files%20in%20the%20codeigniter%20framework.%20If%20you%20are%20not%20sure%20what%20I%20mean%20then%20check%20out%20the%20files%20that%20mak" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2010/07/19/codeigniter-snippets-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter: Using set_value with Form Posts</title>
		<link>http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/</link>
		<comments>http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 10:01:26 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[helpers]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=323</guid>
		<description><![CDATA[Today I came across an interesting bug in a codeigniter application I was working on where I encoded ampersands (&#038;amp) were appearing in a report. I did some rudimentary debugging and realised that for some reason, values from a form were being saved to the database html encoded. I stepped through the code and discovered [...]]]></description>
			<content:encoded><![CDATA[<p>Today I came across an interesting bug in a codeigniter application I was working on where I encoded ampersands (&#038;amp) were appearing in a report. I did some rudimentary debugging and realised that for some reason, values from a form were being saved to the database html encoded.</p>
<p>I stepped through the code and discovered that I was using the <a href="http://codeigniter.com/user_guide/helpers/form_helper.html">set_value()</a> function to retrieve the value posted from the form. This is a no-go I&#8217;m afraid. set_value is supposed to be used to set the values of inputs and textareas in forms within the view itself and as such runs the <a href="http://php.net/manual/en/function.htmlspecialchars.php">htmlspecialchars</a> function across the form post value before returning it. There is a function specifically designed for what I wanted: <a href="http://codeigniter.com/user_guide/libraries/input.html">$this->input-post(fieldname)</a>. Lesson learned.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=CodeIgniter%3A+Using+set_value+with+Form+Posts+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;t=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;title=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;title=CodeIgniter%3A+Using+set_value+with+Form+Posts&amp;summary=Today%20I%20came%20across%20an%20interesting%20bug%20in%20a%20codeigniter%20application%20I%20was%20working%20on%20where%20I%20encoded%20ampersands%20%28%26amp%29%20were%20appearing%20in%20a%20report.%20I%20did%20some%20rudimentary%20debugging%20and%20realised%20that%20for%20some%20reason%2C%20values%20from%20a%20form%20were%20being%20saved%20to%20the%20database%20html%20encoded.%0D%0A%0D%0AI%20stepped%20throug&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;title=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;Title=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;title=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;t=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/&amp;title=CodeIgniter%3A+Using+set_value+with+Form+Posts" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22CodeIgniter%3A%20Using%20set_value%20with%20Form%20Posts%22&amp;body=Link: http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Today%20I%20came%20across%20an%20interesting%20bug%20in%20a%20codeigniter%20application%20I%20was%20working%20on%20where%20I%20encoded%20ampersands%20%28%26amp%29%20were%20appearing%20in%20a%20report.%20I%20did%20some%20rudimentary%20debugging%20and%20realised%20that%20for%20some%20reason%2C%20values%20from%20a%20form%20were%20being%20saved%20to%20the%20database%20html%20encoded.%0D%0A%0D%0AI%20stepped%20throug" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2010/06/21/codeigniter-setvalue-form-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Error CSS Classes</title>
		<link>http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/</link>
		<comments>http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 08:43:46 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[styles]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=146</guid>
		<description><![CDATA[When version 1.7 of CodeIgniter was released, they introduced a new form validation class that vastly simplified things. I particularly liked the new way in which any errors that occurred during form validation were displayed on screen. Where as before, an error message for a field was displayed as follows: &#60;?=$this-&#62;validation-&#62;myfield_error?&#62; It seemed much neater [...]]]></description>
			<content:encoded><![CDATA[<p>When version 1.7 of <a href="http://codeigniter.com/">CodeIgniter</a> was released, they introduced a new form validation class that vastly simplified things. I particularly liked the new way in which any errors that occurred during form validation were displayed on screen.<br />
Where as before, an error message for a field was displayed as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">myfield_error</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>It seemed much neater with the new validation class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?=</span>form_error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myfield'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>What I found however, was there was no simple way to style a particular field if it it had an error. I wanted a similar method to displaying the error message but which would output the error css class name, if there was an error with the field.<br />
After poking around the new validation code, I discovered that creating such a function would require the extension of two of the base files &#8211; the helper form_helper.php would be the place to put the function that I could call from the view and the library form_validation.php would be the place where I could put a function that checks whether a particular field is valid or not.<br />
CodeIgniter provides a way to extend these files easily by placing a file of the same name with the prefix &#8216;MY_&#8217; inside the appropriate folder in the application directory. So, to create the functionality I wanted, I created a MY_form_helper.php and put the following code into it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error_class'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> error_class<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</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: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">===</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$OBJ</span> <span style="color: #339933;">=&amp;</span> _get_validation_object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">''</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$OBJ</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorclass</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</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: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Then I created a MY_Form_Validation.php file and placed the following in it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><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>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MY_Form_validation <span style="color: #000000; font-weight: bold;">extends</span> CI_Form_validation <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> errorclass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_field_data<span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> OR <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_field_data<span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</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;">return</span> <span style="color: #0000ff;">' invalid'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>With these two changes, I was then able to set the classes of my field as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myfield&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&lt;?=set_value('myfield');?&gt;</span></span>&quot; class=&quot;<span style="color: #009900;">&lt;?=error_class<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'myfield'</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #000000; font-weight: bold;">?&gt;</span></span>&quot; /&gt;</pre></div></div>

<p>This kept the method in line with the set_value and the form_error functions and set the class to &#8216;invalid&#8217; when an error occurred.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=CodeIgniter+Error+CSS+Classes+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;t=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;title=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;title=CodeIgniter+Error+CSS+Classes&amp;summary=When%20version%201.7%20of%20CodeIgniter%20was%20released%2C%20they%20introduced%20a%20new%20form%20validation%20class%20that%20vastly%20simplified%20things.%20I%20particularly%20liked%20the%20new%20way%20in%20which%20any%20errors%20that%20occurred%20during%20form%20validation%20were%20displayed%20on%20screen.%20%0D%0AWhere%20as%20before%2C%20an%20error%20message%20for%20a%20field%20was%20displayed%20a&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;title=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;Title=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;title=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;t=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/&amp;title=CodeIgniter+Error+CSS+Classes" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22CodeIgniter%20Error%20CSS%20Classes%22&amp;body=Link: http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A When%20version%201.7%20of%20CodeIgniter%20was%20released%2C%20they%20introduced%20a%20new%20form%20validation%20class%20that%20vastly%20simplified%20things.%20I%20particularly%20liked%20the%20new%20way%20in%20which%20any%20errors%20that%20occurred%20during%20form%20validation%20were%20displayed%20on%20screen.%20%0D%0AWhere%20as%20before%2C%20an%20error%20message%20for%20a%20field%20was%20displayed%20a" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/07/codeigniter-error-css-classes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating PDF Documents in PHP Using Tcpdf</title>
		<link>http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/</link>
		<comments>http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 06:19:42 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=21</guid>
		<description><![CDATA[When developing websites, it is not going to be too long before you are required to generate a pdf for users to download. One usually searches for a suitable library for this and in php, there are a few options out there. My personal favourite, and one that is still receiving regular updates and improvements, [...]]]></description>
			<content:encoded><![CDATA[<p>When developing websites, it is not going to be too long before you are required to generate a pdf for users to download. One usually searches for a suitable library for this and in php, there are a few options out there. My personal favourite, and one that is still receiving regular updates and improvements, is <a href="http://www.tcpdf.org/" target="_blank">tcpdf</a>.</p>
<p>There always seems to be a trade-off between flexibility and ease of use with these libraries and tcpdf seems to lean more towards the flexibility side of things. I prefer this, as there would be nothing worse that committing oneself to a particular library, only to find that it is not possible to generate a particulr report further down the track. On top of this, the library is available in PHP4 and PHP5 versions and is open source, should one need to tweak it any way.</p>
<p>Installation is pretty straight forward for and there are <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_installation">suitable instructions</a> telling you how. In my case, however, I am using the <a href="http://codeigniter.com/">CodeIgniter</a> framework and needed to take some additional steps in order to use it. If anyone else is also using CodeIgniter, here is how I do it:</p>
<ol>
<li>Unpack the tcpdf installation package into your  system/plugins folder. This will give you a tcpdf directory in the plugins directory.</li>
<li>Create a tcpdf_pi.php file inside the plugins directory. Place the following code in it:</li>
</ol>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><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: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tcpdf/config/lang/eng.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tcpdf/tcpdf.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Extend the TCPDF class to create custom Header and Footer</span>
<span style="color: #000000; font-weight: bold;">class</span> OnemoretakePDF <span style="color: #000000; font-weight: bold;">extends</span> TCPDF <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> tcpdf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> OnemoretakePDF <span style="color: #009900;">&#40;</span>PDF_PAGE_ORIENTATION<span style="color: #339933;">,</span> PDF_UNIT<span style="color: #339933;">,</span> PDF_PAGE_FORMAT<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">?&gt;</span></pre></td></tr></table></div>

<p>Here, we basically instantiate tcpdf and pass in a few of the default values. You may be wondering why I have extended the TCPDF class and have not just instantiated it directly. Well, I shall come to that later.</p>
<p>To use this in CodeIgniter, you load the plugin and then create an instance of  it as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">plugin</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'tcpdf'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span> <span style="color: #339933;">=</span> tcpdf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The next step really, is to visit the <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html" target="_blank">documentation for tcpdf</a>. It is not the easiest to follow set of documentation there is, as it has been generated directly from the code, although there are<a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples" target="_blank"> several examples</a> that you can pull apart to learn more. The premise here is to create a new pdf page and plot what you want on that page. This can be done directly with commands like Text() and Line() which use coordinates directly or you can also use Cell() and MultiCell() which allow you to draw using a cell system like a table and utilise borders and alignment appropriately. For those who just cannot get their heads around plotting on a page, there are commands to plot HTML, although support for styles is limited, so don&#8217;t expect to recreate a fancy webpage layout by throwing the html at it. I found that with a little bit of lateral thinking, most jobs can be done without the HTML methods anyhow.</p>
<p>What took me a little time to get used to, is that the coordinate system is not in pixels but by default, in millimetres. This actually makes a lot of sense, as we are creating for print here, not screen. This makes it very awkward if you are working off a design done in photoshop or similar and want to get the dimensions just right. However, a trick I soon learned was to print that image directly to a pdf and then you can use the measurement tools in your pdf reader (<a href="http://www.foxitsoftware.com/pdf/rd_intro.php" target="_blank">Foxit reader</a> has such a tool) to measure the correct distance in millimetres.</p>
<p>The API for tcpdf is extensive and with it, one can achieve most tasks. One thing to note, however is that to create a standard header and footer for your document, you need to override the default header and footer methods in the main tcpdf class. This is why, in the code above, I extended the tcpdf class. It will give us the opportunity to override these methods as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> OnemoretakePDF <span style="color: #000000; font-weight: bold;">extends</span> TCPDF <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//Page header</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">Header</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//header plotting code here</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Page footer</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//footer plotting code here</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>My biggest gripe about this library is that the documentation does not give enough detail. Coupled with that, the forum is a SourceForge forum, which frankly I find very difficult to find anything in. It would be great if there was a way to get more detail, perhaps a wiki would benefit the project a great deal &#8211; I am sure there is a lot of detailed knowledge out there about the ins and outs of the library, its just that there is no way to tap into it.</p>
<p>You can&#8217;t complain too much however, this project provides a very powerful pdf creation library. I have had experience with Microsoft.Net libraries of a similar nature and you can end up paying quite a lot for them. Not to mention they tend be way more restricted as to what is possible.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Creating+PDF+Documents+in+PHP+Using+Tcpdf++-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;t=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+&amp;summary=When%20developing%20websites%2C%20it%20is%20not%20going%20to%20be%20too%20long%20before%20you%20are%20required%20to%20generate%20a%20pdf%20for%20users%20to%20download.%20One%20usually%20searches%20for%20a%20suitable%20library%20for%20this%20and%20in%20php%2C%20there%20are%20a%20few%20options%20out%20there.%20My%20personal%20favourite%2C%20and%20one%20that%20is%20still%20receiving%20regular%20updates%20and%20imp&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;Title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;t=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/&amp;title=Creating+PDF+Documents+in+PHP+Using+Tcpdf+" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Creating%20PDF%20Documents%20in%20PHP%20Using%20Tcpdf%20%22&amp;body=Link: http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A When%20developing%20websites%2C%20it%20is%20not%20going%20to%20be%20too%20long%20before%20you%20are%20required%20to%20generate%20a%20pdf%20for%20users%20to%20download.%20One%20usually%20searches%20for%20a%20suitable%20library%20for%20this%20and%20in%20php%2C%20there%20are%20a%20few%20options%20out%20there.%20My%20personal%20favourite%2C%20and%20one%20that%20is%20still%20receiving%20regular%20updates%20and%20imp" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/02/28/creating-pdf-documents-in-php-using-tcpdf/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
