<?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; PHP</title>
	<atom:link href="http://www.onemoretake.com/category/php/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>IIS7 WordPress and Friendly URLs</title>
		<link>http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/</link>
		<comments>http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 06:54:54 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/</guid>
		<description><![CDATA[As a developer who uses Vista as their main OS, I have always found developing php sites a little bit awkward. Php never liked to play nicely with IIS and unless you installed and used Apache, friendly URLs were even more difficult to get working. I use IIS extensively for ASP.NET development and I never [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer who uses Vista as their main OS, I have always found developing php sites a little bit awkward. Php never liked to play nicely with IIS and unless you installed and used Apache, friendly URLs were even more difficult to get working. I use IIS extensively for ASP.NET development and I never liked having both Apache and IIS installed together as they seemed to lock horns at every opportunity. My answer until now was to use <a href="http://www.jcxsoftware.com/vs.php" target="_blank">VS.php</a>, which runs an instance of Apache on demand, so I only have to use Apache when I need to. This was great for the most part but last week I had the situation where I was trying to work on both an ASP.NET project and a WordPress project at the same time. Stopping and starting web servers every few minutes was getting a little dull.</p>
<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/08/rewrite.png"><img title="rewrite" style="border-right: 0px; border-top: 0px; display: inline; margin: 10px 25px 0px 0px; border-left: 0px; border-bottom: 0px" height="198" alt="rewrite" src="http://www.onemoretake.com/wp-content/uploads/2009/08/rewrite_thumb.png" width="314" align="left" border="0" /></a>This spurred me on to take some time to see what all <a href="http://www.itworld.com/development/73001/how-microsoft-made-php-suck-less-windows" target="_blank">the fuss about IIS7 and php was really about</a>. I was pleasantly surprised. Since Vista SP1, it is possible to configure IIS to run php using FastCGI. I won’t go into the detail here, <a href="http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/" target="_blank">there are plenty of examples on how to configure php</a> in this way. Needless to say, it was not too difficult and I had a test phpinfo(); page displaying in no time. What’s particularly great is that Microsoft has been doing some great work getting php to run as quickly and efficiently as it can on IIS. If you are happy running php version 5.3, over at <a href="http://windows.php.net/" target="_blank">Php for Windows</a>, you can pick up a version that has been compiled in Visual Studio 2008 which means faster and more stable than before.</p>
<p>The next step in my investigation was to see what could be done with the new <a href="http://www.iis.net/extensions/URLRewrite" target="_blank">url rewrite module for IIS</a>. Another easy thing to install. What’s more, it has the ability to import .htaccess files. I use these extensively when using Apache and I already had one for the WordPress site I was working on. Importing rules is a pleasure because of the neat interface that shows you which rules it can convert and which it cannot. Editing the original .htaccess directives on-screen allows you to fix those rules it is having trouble with. In my case it was just the RewriteBase, which I could happily remove without worrying about it.</p>
<p>One click of the ‘apply’ button and I was up add running. The site was responsive and low and behold, no issues with the friendly urls. Too easy!</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=IIS7+Wordpress+and+Friendly+URLs+-+&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/08/31/iis7-wordpress-and-friendly-urls/&amp;t=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs&amp;summary=As%20a%20developer%20who%20uses%20Vista%20as%20their%20main%20OS%2C%20I%20have%20always%20found%20developing%20php%20sites%20a%20little%20bit%20awkward.%20Php%20never%20liked%20to%20play%20nicely%20with%20IIS%20and%20unless%20you%20installed%20and%20used%20Apache%2C%20friendly%20URLs%20were%20even%20more%20difficult%20to%20get%20working.%20I%20use%20IIS%20extensively%20for%20ASP.NET%20development%20and%20I%20&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/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&amp;Title=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&amp;t=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/&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/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" 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/08/31/iis7-wordpress-and-friendly-urls/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22IIS7%20Wordpress%20and%20Friendly%20URLs%22&amp;body=Link: http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A As%20a%20developer%20who%20uses%20Vista%20as%20their%20main%20OS%2C%20I%20have%20always%20found%20developing%20php%20sites%20a%20little%20bit%20awkward.%20Php%20never%20liked%20to%20play%20nicely%20with%20IIS%20and%20unless%20you%20installed%20and%20used%20Apache%2C%20friendly%20URLs%20were%20even%20more%20difficult%20to%20get%20working.%20I%20use%20IIS%20extensively%20for%20ASP.NET%20development%20and%20I%20" 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/08/31/iis7-wordpress-and-friendly-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check your PHP UTF-8 Checklist</title>
		<link>http://www.onemoretake.com/2009/04/19/check-your-php-utf-8-checklist/</link>
		<comments>http://www.onemoretake.com/2009/04/19/check-your-php-utf-8-checklist/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 01:53:31 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[text encoding]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=220</guid>
		<description><![CDATA[I spent way too long this weekend on a problem that had such a simple solution. I guess this issue may have been a little to do with the fact that I use the CodeIgniter framework, which does so much of the hard work for you. it&#8217;s easy to get complaisant. I have been working [...]]]></description>
			<content:encoded><![CDATA[<p>I spent way too long this weekend on a problem that had such a simple solution. I guess this issue may have been a little to do with the fact that I use the <a href="http://codeigniter.com">CodeIgniter framework</a>, which does so much of the hard work for you. it&#8217;s easy to get complaisant.</p>
<p>I have been working with text files that contain multi-byte characters and had previously ensured that my database and tables were setup for UTF-8 and that everything in codeigniter was correctly configured. Yet still I was getting invalid character errors on the database insert.</p>
<p>As the text files were of varying formats, including excel&#8217;s unicode csv format, I had already ensured that the reading of the text file also included conversion to UTF-8. Thanks to the <a href="http://www.practicalweb.co.uk/blog/08/05/18/reading-unicode-excel-file-php">script on Practical Web Ltd</a>, I was attempting to detect the format of the files and converting them to UTF-8 on the fly. Yet still I was getting invalid character errors on the database insert.</p>
<p>I even ran through my code line by line and checked for any string manipulation I was doing using non-safe string functions. Yet still I was getting invalid character errors on the database insert.</p>
<p>If I had any decent amount of hair left, I would certainly have pulled it all out by the time I figured out what was wrong. I only discovered the answer by accident when I decided to remove the string manipulation altogether. As soon as I did that, it worked a treat. Had I discovered a bug in the multibyte string functions? No. </p>
<p>I had not checked the default encoding of mbstring.</p>
<p>So please, make sure it is on your check list of things to do when dealing with multi-byte strings. Set up the default correctly or religiously use the encoding parameter in the multi-byte string functions.</p>
<p>Even better, you could use the great checklist on nicknettleton.com (see below), which seems to cover everything.</p>
<p>I totally deserved the dunce hat. </p>
<p><strong>Edit:</strong> Looks like the link on nicknettleton.com is no longer available (thanks @Les). A little digging around led me to the same <a href="http://developer.loftdigital.com/blog/php-utf-8-cheatsheet">checklist on php UTF-8</a> on another site.</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=Check+your+PHP+UTF-8+Checklist+-+&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/04/19/check-your-php-utf-8-checklist/&amp;t=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&amp;title=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&amp;title=Check+your+PHP+UTF-8+Checklist&amp;summary=I%20spent%20way%20too%20long%20this%20weekend%20on%20a%20problem%20that%20had%20such%20a%20simple%20solution.%20I%20guess%20this%20issue%20may%20have%20been%20a%20little%20to%20do%20with%20the%20fact%20that%20I%20use%20the%20CodeIgniter%20framework%2C%20which%20does%20so%20much%20of%20the%20hard%20work%20for%20you.%20it%27s%20easy%20to%20get%20complaisant.%0D%0A%0D%0AI%20have%20been%20working%20with%20text%20files%20that%20c&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/04/19/check-your-php-utf-8-checklist/&amp;title=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&amp;Title=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&amp;title=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&amp;t=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/&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/04/19/check-your-php-utf-8-checklist/&amp;title=Check+your+PHP+UTF-8+Checklist" 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/04/19/check-your-php-utf-8-checklist/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Check%20your%20PHP%20UTF-8%20Checklist%22&amp;body=Link: http://www.onemoretake.com/2009/04/19/check-your-php-utf-8-checklist/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20spent%20way%20too%20long%20this%20weekend%20on%20a%20problem%20that%20had%20such%20a%20simple%20solution.%20I%20guess%20this%20issue%20may%20have%20been%20a%20little%20to%20do%20with%20the%20fact%20that%20I%20use%20the%20CodeIgniter%20framework%2C%20which%20does%20so%20much%20of%20the%20hard%20work%20for%20you.%20it%27s%20easy%20to%20get%20complaisant.%0D%0A%0D%0AI%20have%20been%20working%20with%20text%20files%20that%20c" 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/04/19/check-your-php-utf-8-checklist/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Revisited: Tcpdf &#8211; Variable Height Table Rows With MultiCell</title>
		<link>http://www.onemoretake.com/2009/03/27/revisited-tcpdf-variable-height-table-rows-with-multicell/</link>
		<comments>http://www.onemoretake.com/2009/03/27/revisited-tcpdf-variable-height-table-rows-with-multicell/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:12:12 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[tcpdf]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=205</guid>
		<description><![CDATA[A few weeks ago I wrote an article about creating variable height table rows using tcpdf. It was a neat solution and I liked it, which was the reason I blogged about it in the first place. However, it turns out that &#8216;sharing the love&#8217; is not the only reason to blog about these things. [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I wrote <a href="http://www.onemoretake.com/2009/03/09/tcpdf-variable-height-table-rows-with-multicell/">an article about creating variable height table rows</a> using <a href="http://www.tcpdf.org/">tcpdf</a>. It was a neat solution and I liked it, which was the reason I blogged about it in the first place. However, it turns out that &#8216;sharing the love&#8217; is not the only reason to blog about these things. It can also be a learning experience thanks to the commenting from you out there in the interwebs.</p>
<p>The <a href="http://www.onemoretake.com/2009/03/09/tcpdf-variable-height-table-rows-with-multicell/comment-page-1/#comment-23">particular comment in question</a>, from mike, made me realise that there was a bit of a flaw in my neat idea &#8211; page breaks. Because I was first drawing the text, the automatic page breaks played havoc with the positioning when it came to drawing the borders. If the text was so long that it wrapped across enough lines to cause a page break, when I tried to reposition to draw the borders I was in completely the wrong place and it <a href="http://en.wikipedia.org/wiki/Pete_Tong">all went a little Pete Tong</a>.</p>
<p>Still, not deterred by this little setback, I re-looked at the problem and have come up with a different approach that solves this problem and adds the ability to do a few more things.</p>
<p>When I relooked at the documentation, I discovered the useful little function: <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html#methodgetNumLines">getNumLines()</a>. This actually allows us to determine how many lines a string of text will take up, given a particular width. In effect, it allows us to do what I was using MultiCell to return, without actually drawing anything. This lets us to determined the maximum cell height with one line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linecount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell1data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell2data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell3data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now that we know the cell height before we have drawn anything, we can use <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html#methodMultiCell">MultiCell()</a> to draw the text and the borders at the same time.</p>
<p>This was not the end, however. My particular implementation was a grid of data that had borders between the column and not between the rows. All very pretty until that automatic page break happened and gave us a grid of data without a border at the bottom. To add insult to injury, the new page ended up with a grid of data with no border at the top! </p>
<p>To solve this, I needed to know if the row was going to be the first of the page, so I could draw the bottom border on the previous row and give the new row a top border. With the use of the page dimensions I could work this out:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dimensions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPageDimensions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hasBorder</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//flag for fringe case</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$rowcount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//work out the number of lines required</span>
	<span style="color: #000088;">$rowcount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell1data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell2data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumLines</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell3data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$startY</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$startY</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rowcount</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bm'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hk'</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;">//this row will cause a page break, draw the bottom border on previous row and give this a top border</span>
		<span style="color: #666666; font-style: italic;">//we could force a page break and rewrite grid headings here</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hasborder</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$hasborder</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</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;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">240</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'T'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//draw bottom border on previous row</span>
			<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Ln</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: #000088;">$borders</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'LTR'</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: #009900;">&#40;</span><span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$startY</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rowcount</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bm'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hk'</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;">//fringe case where this cell will just reach the page break</span>
		<span style="color: #666666; font-style: italic;">//draw the cell with a bottom border as we cannot draw it otherwise</span>
		<span style="color: #000088;">$borders</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'LRB'</span><span style="color: #339933;">;</span>	
		<span style="color: #000088;">$hasborder</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//stops the attempt to draw the bottom border on the next row</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//normal cell</span>
		<span style="color: #000088;">$borders</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'LR'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//now draw it</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$rowcount</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell1data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$borders</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$rowcount</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell2data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$borders</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$rowcount</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell3data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$borders</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Ln</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">240</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'T'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//last bottom border</span></pre></div></div>

<p>Note that there is a fringe case that I came across. This was when the row would not cause a page break as it was exactly the height of the remaining space. Any attempt to draw the bottom border with a separate call would cause a page break. I solved this by ensuring in that particular case, the cell was drawn with the bottom border already.</p>
<p>What gives this method more power (apart from actually working) is that we know when there is going to be a new page and we could choose to force a new page and if we wanted. We could then re-plot the grid headings before creating the row. That way we can have the grid headings on every page.</p>
<p>I am determined to get a water-tight solution to this problem and I think this gets us closer. If you do find any problems with it, let me know and I will see if we can solve them. Thanks for your feedback.</p>
<p><strong>Update:</strong> <a href="http://www.oceanit.co.za/" rel="external">Bretton Eveleigh</a> has written a class that encapsulates this and other helper methods into a format that makes creating tables with Tcpdf much easier. See the comments below for the link. Thanks Bretton.</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=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell+-+&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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;t=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell&amp;summary=A%20few%20weeks%20ago%20I%20wrote%20an%20article%20about%20creating%20variable%20height%20table%20rows%20using%20tcpdf.%20It%20was%20a%20neat%20solution%20and%20I%20liked%20it%2C%20which%20was%20the%20reason%20I%20blogged%20about%20it%20in%20the%20first%20place.%20However%2C%20it%20turns%20out%20that%20%27sharing%20the%20love%27%20is%20not%20the%20only%20reason%20to%20blog%20about%20these%20things.%20It%20can%20also%20be&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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;Title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;t=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/&amp;title=Revisited%3A+Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Revisited%3A%20Tcpdf%20-%20Variable%20Height%20Table%20Rows%20With%20MultiCell%22&amp;body=Link: http://www.onemoretake.com/2009/03/27/revisited-tcpdf-variable-height-table-rows-with-multicell/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A A%20few%20weeks%20ago%20I%20wrote%20an%20article%20about%20creating%20variable%20height%20table%20rows%20using%20tcpdf.%20It%20was%20a%20neat%20solution%20and%20I%20liked%20it%2C%20which%20was%20the%20reason%20I%20blogged%20about%20it%20in%20the%20first%20place.%20However%2C%20it%20turns%20out%20that%20%27sharing%20the%20love%27%20is%20not%20the%20only%20reason%20to%20blog%20about%20these%20things.%20It%20can%20also%20be" 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/27/revisited-tcpdf-variable-height-table-rows-with-multicell/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Tcpdf &#8211; Variable Height Table Rows With MultiCell</title>
		<link>http://www.onemoretake.com/2009/03/09/tcpdf-variable-height-table-rows-with-multicell/</link>
		<comments>http://www.onemoretake.com/2009/03/09/tcpdf-variable-height-table-rows-with-multicell/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 05:25:24 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=153</guid>
		<description><![CDATA[This post as been superseded. Please see my new post on the subject. During my use of the excellent tcpdf library for creating pdf documents with php, I came across an interesting problem when creating a pdf featuring a grid of data. Although I could have use an html grid to present the data, I [...]]]></description>
			<content:encoded><![CDATA[<p>This post as been superseded. Please see my <a href="http://www.onemoretake.com/2009/03/27/revisited-tcpdf-variable-height-table-rows-with-multicell/">new post on the subject</a>.</p>
<p>During my use of the excellent <a href="http://www.tcpdf.org/">tcpdf</a> library for creating pdf documents with php, I came across an interesting problem when creating a pdf featuring a grid of data. Although I could have use an html grid to present the data, I was trying to avoid the use of html and keep to the Cell(), MultiCell(), Text() etc. methods to render the document.</p>
<p>The content of some of the cells in this particular grid were quite long and so some wrapping of text would (and needed to) occur. The MultiCell method handles this and will wrap the text, expanding accordingly. Now I was trying to make a grid row, so needed all of the cells to be the same height &#8211; and there lay the problem &#8211; I did not know how high to make the other cells. It was a chicken and egg situation: I needed to know the height of the cell before drawing them but did not know how high they needed to be until after I had drawn them.</p>
<p>I studied the <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html">documentation</a> hard but realised that the answer was not to try and generate the cells, borders and all, in one pass. I could achieve what I needed by drawing each row twice &#8211; once for the content and once for the borders.</p>
<p>The <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html#methodMultiCell">MultiCell function</a> kindly returns the height that the cell was drawn, so by remembering the maximum value it was when drawing a row of cells, I could then go back and draw the borders to that maximum height:</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
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$cellcount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//write text first</span>
	<span style="color: #000088;">$startX</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$startY</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//draw cells and record maximum cellcount</span>
	<span style="color: #666666; font-style: italic;">//cell height is 6 and width is 80</span>
	<span style="color: #000088;">$cellcount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell1data'</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: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</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: #000088;">$cellcount</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$maxnocells</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cellcount</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$cellcount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell2data'</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: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</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: #000088;">$cellcount</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$maxnocells</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cellcount</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$cellcount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cell3data'</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: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</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: #000088;">$cellcount</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$maxnocells</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cellcount</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetXY</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$startX</span><span style="color: #339933;">,</span><span style="color: #000088;">$startY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//now do borders and fill</span>
	<span style="color: #666666; font-style: italic;">//cell height is 6 times the max number of cells</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'LR'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'LR'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span><span style="color: #000088;">$maxnocells</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'LR'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Ln</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note that the last parameter I set in MultiCell is set to 0 which means that no new line occurs once a cell is drawn. This means that the cells will appear side-by-side and also means that I need to manually create the new line when I finish drawing the row.</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=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell+-+&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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;t=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell&amp;summary=This%20post%20as%20been%20superseded.%20Please%20see%20my%20new%20post%20on%20the%20subject.%0D%0A%0D%0ADuring%20my%20use%20of%20the%20excellent%20tcpdf%20library%20for%20creating%20pdf%20documents%20with%20php%2C%20I%20came%20across%20an%20interesting%20problem%20when%20creating%20a%20pdf%20featuring%20a%20grid%20of%20data.%20Although%20I%20could%20have%20use%20an%20html%20grid%20to%20present%20the%20data%2C%20I%20w&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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;Title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;t=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/&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/09/tcpdf-variable-height-table-rows-with-multicell/&amp;title=Tcpdf+-+Variable+Height+Table+Rows+With+MultiCell" 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/09/tcpdf-variable-height-table-rows-with-multicell/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Tcpdf%20-%20Variable%20Height%20Table%20Rows%20With%20MultiCell%22&amp;body=Link: http://www.onemoretake.com/2009/03/09/tcpdf-variable-height-table-rows-with-multicell/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A This%20post%20as%20been%20superseded.%20Please%20see%20my%20new%20post%20on%20the%20subject.%0D%0A%0D%0ADuring%20my%20use%20of%20the%20excellent%20tcpdf%20library%20for%20creating%20pdf%20documents%20with%20php%2C%20I%20came%20across%20an%20interesting%20problem%20when%20creating%20a%20pdf%20featuring%20a%20grid%20of%20data.%20Although%20I%20could%20have%20use%20an%20html%20grid%20to%20present%20the%20data%2C%20I%20w" 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/09/tcpdf-variable-height-table-rows-with-multicell/feed/</wfw:commentRss>
		<slash:comments>10</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>
