<?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>Flipflops.org &#187; Tutorial</title>
	<atom:link href="http://www.flipflops.org/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flipflops.org</link>
	<description>Flipflops.org is about web development and fairly conceptual art</description>
	<lastBuildDate>Sat, 05 Jun 2010 22:46:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Two CakePHP behaviours to extend MeioUpload</title>
		<link>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/</link>
		<comments>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:53:24 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/</guid>
		<description><![CDATA[I&#8217;ve been using the the Meio Upload Behaviour for a while as its a very handy piece of code, but as is so often the case it doesn&#8217;t do quite what I need. In the past I&#8217;ve got round this by hacking together a kind of supporting framework in app_controller and scattered about in my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the the <a href="http://www.meiocodigo.com/projects/meioupload/">Meio Upload Behaviour</a> for a while as its a very handy piece of code, but as is so often the case it doesn&#8217;t do quite what I need. In the past I&#8217;ve got round this by hacking together a kind of supporting framework in app_controller and scattered about in my models. But the other day I came across the <a href="http://github.com/jrbasso/MeioUpload/tree/master">newest version of the code by Juan Basso  on Github</a> and decided to dump my mess of spaghetti code and start from scratch.</p>
<h2>Aims</h2>
<p>The idea is that each model can have its own uploads with their own defaults, for example: </p>
<ul>
<li>Products might need to generate images at 3 different sizes with the smallest zoom cropped.</li>
<li>News items might have 2 image sizes but also need to upload a PDF press release.</li>
</ul>
<p>All of the uploaded files can be viewed and managed centrally from the Upload model.</p>
<p>The changes I wanted to make were as follows:</p>
<ol>
<li>Use a single Uploads table attached to multiple models (<a href="http://bakery.cakephp.org/articles/view/polymorphic-behavior">using the Polymorphic behaviour</a>)</li>
<li>The ability to do multiple uploads at once</li>
<li>Rename my uploaded files</li>
<li>Have an UploadVariants model / table with meta information about the thumbnails</li>
<li>Be able to use more of the PHPThumb image options and use them on a per thumbnail basis.</li>
</ol>
<p>Rather than just take the behaviour and start writing on top of it, I decided to extend the original behaviour (yes you can do this in CakePHP &#8211; its just easy to get absorbed in the framework and forget it) and then create an additional behaviour that manages the multiple uploads.</p>
<p>The underlying requirements are quite simple:</p>
<ul>
<li><a href="http://www.meiocodigo.com/projects/meioupload/">Meio Upload Behaviour</a></li>
<li><a href="http://bakery.cakephp.org/articles/view/phpthumb-component">Nate Constant’s phpThumb Component </a></li>
<li><a href="http://bakery.cakephp.org/articles/view/polymorphic-behavior"><strike>Polymorphic Behaviour</strike></a></li>
<li><a href="http://phpthumb.sourceforge.net/">PHPThumb</a></li>
</ul>
<p>(<strong>Note 09/07/2009</strong> you don&#8217;t actually need the Polymorphic Behaviour, unless you want to do fancy things with your finds)</p>
<p>And my two new behaviours:</p>
<ul>
<li><a href="http://www.flipflops.org/example/je_meio_upload.php.txt">je_meio_upload.php</a></li>
<li><a href="http://www.flipflops.org/example/je_meio_upload_polymorphic.php.txt">je_meio_upload_polymorphic.php</a></li>
</ul>
<p><strong>At the end of the article is a link to let you download a zipped working CakePHP app with everything in place</strong></p>
<h2>The models</h2>
<p>First things first. The database tables on which my models are based.</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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
MySQL Backup
Source Host:           localhost
Source Server Version: 5.0.51b-community-nt
Source Database:       je_meio
Date:                  2009/06/29 15:39:15
*/</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> FOREIGN_KEY_CHECKS<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>;
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #808080; font-style: italic;"># Table structure for products</span>
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> products;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`products`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`title`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;
&nbsp;
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #808080; font-style: italic;"># Table structure for upload_variants</span>
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> upload_variants;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`upload_variants`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`upload_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`variant`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filename`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`quick_type`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`width`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`height`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;
&nbsp;
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #808080; font-style: italic;"># Table structure for uploads</span>
<span style="color: #808080; font-style: italic;">#----------------------------</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> uploads;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`uploads`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`class`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'Upload'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`foreign_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`alt`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filename`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`dir`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`mimetype`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`quick_type`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`filesize`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`position`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`height`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`width`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`processed`</span> tinyint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_by`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`created_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`modified_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`class`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`class`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`foreign_id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;</pre></td></tr></table></div>


<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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">class</span> Upload <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//The Associations below have been created with all possible keys, those that are not needed can be removed</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'UploadVariant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'UploadVariant'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'upload_id'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'dependent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'exclusive'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'finderQuery'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'counterQuery'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$actsAs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Polymorphic'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'JeMeioUpload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files/uploads'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'create_directory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'max_size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2097152</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'max_dimension'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'w'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'thumbnailQuality'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'useImageMagick'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'imageMagickPath'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/usr/bin/convert'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'allowed_mime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'image/gif'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/pjpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'allowed_ext'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.jpg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'thumbsizes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'small'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'medium'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">220</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">220</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'large'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">800</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'default_class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'random_filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
         <span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the Upload model, just include the Polymorphic behaviour and JeMeioUpload instead of MeioUpload. You could actually use the same defaults as the MeioUpload behaviour itself but there are two additional defaults  <em>&#8216;default_class&#8217; => &#8216;Upload&#8217;</em>, and <em>&#8216;random_filename&#8217; => true</em>. These both refer to renaming files. As the behaviour can be used to manage uploads from multiple models in a single table it allows you to set the default Upload model. You can also set whether or not you want the files to have the meaningful part replaced with a random string.</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UploadVariant <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'UploadVariant'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//The Associations below have been created with all possible keys, those that are not needed can be removed</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$belongsTo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Upload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'upload_id'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The UploadVariant Model is just as it was baked.</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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Product <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Product'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$validate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notempty'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'Upload'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span>    
            <span style="color: #0000ff;">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'foreign_id'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'conditions'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'dependent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Upload.position ASC'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$actsAs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
     <span style="color: #0000ff;">'JeMeioUploadPolymorphic'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$jeMeioUploadParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files/uploads/'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'create_directory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'allowed_mime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/pjpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'allowed_ext'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.jpg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.jpeg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'thumbsizes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'small'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'large'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">800</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
           <span style="color: #0000ff;">'shop'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">265</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">265</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'random_filename'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Product is a test model set up to demonstrate the multiple uploads and the Polymorphic association to the Upload model. In this case the meaningful part of the filenames will not be replaced with a random string and the &#8217;small&#8217; thumbnail will be zoom cropped. To find out more about <em>image_options</em> you will need to check the PHPThumb component and the documentation PHPThumb itself (play about and experiment) &#8211; what you can and can&#8217;t do will also be effected by whether or not you have ImageMagick on your server.</p>
<h2>The Controllers</h2>
<p>You don&#8217;t need to make any changes to your controllers at all.</p>
<h2>The Views</h2>
<p>There is nothing complicated in the views at all. Just remember to set them up properly for uploads.</p>
<h3>The uploads/add.ctp</h3>

<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;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;fieldset&gt;
 		&lt;legend&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/legend&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/fieldset&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>The products/add.ctp</h3>
<p>This view allows up to 3 uploads to be stored in the associated Upload model.</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;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;fieldset&gt;
 		&lt;legend&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/legend&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.0.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.1.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload.3.filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/fieldset&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h2>Summary</h2>
<p>The one part I&#8217;m not terribly happy with at the moment is error messages returning to the views in the Polymorphic associations (e.g. Product example). At the moment if an image or upload can&#8217;t be processed then there is no warning or error message. At the moment this is compromise I&#8217;m willing to live with. </p>
<p>I could certainly build some kind of component scaffold or something to go in the controllers to return an error message but I think the gain in responsiveness would probably be outweighed by the added complexity. Right now I can&#8217;t figure out an elegant way to get error messages from back to the views &#8211; if anybody has any suggestions please let me know.<br />
(<strong>Note</strong> if you are uploading straight into the Upload model then the error messages are unaffected)</p>
<p>There is also the problem of what do you do when in a situation like the following: If you add a new Product successfully but the associated upload has problems? Ideally you would want to redirect to the edit view for that Product but there seems to be no easy way of doing this from a Model / Behaviour.</p>
<p>One solution that I have implemented in the past is to create dedicated views for uploading &#8211; so if you do hack your hacks are easy to manage.</p>
<p><strong>I&#8217;ve baked a quick and dirty demo that you can download <a href="http://www.flipflops.org/example/je_meio_upload.zip">here</a></strong>. Its so basic that it doesn&#8217;t even show the uploaded images!</p>
<h2>Todo List</h2>
<ul>
<li>
A helper to generate things like uploads fields complete with delete checkboxes and thumbnail images.</li>
<li>
Deleting the via the Polymorphic association  (don&#8217;t think this works right now)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2009/06/29/two-cakephp-behaviours-to-extend-meioupload/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Multiple CMS systems with Symbolic Links</title>
		<link>http://www.flipflops.org/2007/06/19/multiple-cms-systems-with-symbolic-links/</link>
		<comments>http://www.flipflops.org/2007/06/19/multiple-cms-systems-with-symbolic-links/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 12:08:20 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Things]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2007/06/19/multiple-cms-systems-with-symbolic-links/</guid>
		<description><![CDATA[If you are a web developer you will very often be in the situation where you have to manage a server that has a large number of websites running on it all of which are running the same Content Management System. So far so good, everything is in one place and you know how your [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer you will very often be in the situation where you have to manage a server that has a large number of websites running on it all of which are running the same Content Management System. So far so good, everything is in one place and you know how your server is setup.</p>
<p>But what happens when you find a bug in the CMS system or you need to upgrade all the sites? You probably have a simple proceedure in place that goes something like this:</p>
<ol>
<li>Update &#038; Test the development copy of the website.</li>
<li>Copy the website to a file server into a new directory (named by date or version).</li>
<li>Upload the files from the file server to the live web server.</li>
</ol>
<p>The idea being that you always have an exact copy of the files on your live server on a local server, and that you can easily revert to an seralier version should you have to.</p>
<p>(This is assuming you aren&#8217;t using a CVS system, just a well organised file system and some good procedures.)</p>
<p>If you only have a couple of websites this isn&#8217;t a problem, but if you have 20 or 60 then suddenly you can end up having to deal with a lot of operations. If you host on a Linux server the solution to your problems is called a <strong>Symbolic Link</strong>. When I think of Symbolic Links I think of Alice in Wonderland and magic tunnels.</p>
<p>Wikipedia describes <a href="http://en.wikipedia.org/wiki/Symbolic_link">Symbolic Links</a> like this:</p>
<blockquote><p>
In computing, a symbolic link (often shortened to symlink and also known as a soft link) consists of a special type of file that serves as a reference to another file or directory. Unix-like operating systems in particular often feature symbolic links.</p>
<p>Unlike a hard link, a symbolic link does not point directly to data, but merely contains a symbolic path which an operating system uses to identify a hard link (or another symbolic link). Thus, when a user removes a symbolic link, the file to which it pointed remains unaffected. (In contrast, the removal of a hard link will result in the removal of the file if that file has no other hard links.) Systems can use symbolic links to refer to files even on other mounted file systems. The term orphan refers to a symbolic link whose target does not exist.</p>
<p>Symbolic links operate transparently, which means that their implementation remains invisible to applications. When a program opens, reads, or writes a symbolic link, the operating system will automatically redirect the relevant action to the target of the symlink. However, functions do exist to detect symbolic links so that applications may find and manipulate them.</p>
<p>Users should pay careful attention to the maintenance of symbolic links. Unlike hard links, if the target of a symbolic link is removed, the data vanishes and all links to it become orphans. Conversely, removing a symbolic link has no effect on its target.
</p></blockquote>
<p>Personally I don&#8217;t find this very helpful &#8211; what it means in practice however is that you can have create what appears to be a directory, but the contents of that directory are stored somewhere completely different. Even better you can create lots of these directories each of which appears unique, but which in fact all point to the same data. </p>
<p>Why have 60 copies of the same identical data and update it 60 times when instead you can update the source data once?</p>
<h2>Example</h2>
<p><img src='http://www.flipflops.org/wp-content/uploads/2007/06/symbolic_links.gif' alt='Symbolic Links' /></p>
<p>This is screenshot of a Linux directory listing illustrating the symbolically linked directories all pointing to the same files. To update all the CMS systems all you would need to do is update a single directory. This is a very simplified view of course, to run a system like this in real life each website needs its own configuration file(s) etc.</p>
<p>Looking at the file system via FTP you see this:</p>
<p><img src='http://www.flipflops.org/wp-content/uploads/2007/06/ftp.gif' alt='FTP screenshot' /></p>
<h2>How to create a Symbolic Link</h2>
<p>To create a symbolic link you need access to the command prompt &#8211; this will usually be via SSH. I use a small program called <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">putty</a> to do this.</p>
<p>The command is: <strong>ln -s source_file myfile</strong> where <em>source_file</em> is the file or directory you wish to link to and <em>myfile</em> is the name of the symbolic link you wish to create.</p>
<p>This screenshot shows the commands I use to create the symbolic links in the other examples:</p>
<p><img src='http://www.flipflops.org/wp-content/uploads/2007/06/putty.gif' alt='Screenshot of putty in action' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2007/06/19/multiple-cms-systems-with-symbolic-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Bake to Work</title>
		<link>http://www.flipflops.org/2007/02/28/getting-bake-to-work/</link>
		<comments>http://www.flipflops.org/2007/02/28/getting-bake-to-work/#comments</comments>
		<pubDate>Wed, 28 Feb 2007 13:57:32 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Things]]></category>
		<category><![CDATA[bake]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2007/02/28/getting-bake-to-work/</guid>
		<description><![CDATA[A really powerful feature of CakePHP is bake &#8211;  a script located at  /cake/scripts/bake.php &#8211; it is similar in function to the Ruby on Rails Scaffold application &#8211; it is a command line programme that can generate outline or scaffolding code to carry out simple CRUD operations, based solely on your database structure.
I have had quite a [...]]]></description>
			<content:encoded><![CDATA[<p>A really powerful feature of <a href="http://www.cakephp.org">CakePHP</a> is bake &#8211;  a script located at  /cake/scripts/bake.php &#8211; it is similar in function to the <a href="http://www.rubyonrails.org/">Ruby on Rails</a> Scaffold application &#8211; it is a command line programme that can generate outline or scaffolding code to carry out simple CRUD operations, based solely on your database structure.</p>
<p>I have had quite a few problems getting Bake to work reliably, but persevere because it is worth it. I have been developing on a PC running XP Pro and <a href="http://apache2triad.net/">Apache2Triad</a> 2.0.55</p>
<p><strong>On windows there seems to be a bit of an issue with paths and in order to do any baking on an existing project you need to specify the full paths.</strong></p>
<p>[I use the <a href="http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx">Command Window Here</a>  Power Toy for Win XP which makes it easy to get the command prompt to the right place.]</p>
<h3>To create a new cake application</h3>
<ol>
<li>Navigate to <code>\cake\scripts\</code> and open the command prompt.</li>
<li><code>php bake.php -app name_of_application</code></li>
<li>follow the onscreen instructions&#8230;</li>
</ol>
<p>For Example: To create a new application called Flamingo:</p>
<p><code>php bake.php -app flamingo</code></p>
<p><img src="http://www.flipflops.org/wp-content/uploads/2007/02/bake2.gif" alt="bake" /></p>
<p>As you can see bake asks you if its ok to create a skeleton application on the path specified.</p>
<h3>How to bake inside an existing application</h3>
<p>If you want to bake inside an existing application, from the Cake tutorials and articles, it appears that you should be able to just type: <code>php bake.php -app flamingo</code> again, unfortunately this doesn&#8217;t work. Instead you get the following message.</p>
<p><img src="http://www.flipflops.org/wp-content/uploads/2007/02/bake3.gif" alt="how not to bake" /></p>
<p>What you actually need to type is something that includes the full path to your new cake application, something like:</p>
<p><code>php bake.php -app D:\apache2triad\htdocs\ctest\public_html\flamingo</code></p>
<p>If you already have a database structure you will see something like this:</p>
<p><img src="http://www.flipflops.org/wp-content/uploads/2007/02/bake5.gif" alt="Let’s bake" /></p>
<p>If you don&#8217;t yet have a database setup you will be prompted for connection details like this:</p>
<p><img src="http://www.flipflops.org/wp-content/uploads/2007/02/bake4.gif" alt="bake - no database" /></p>
<p><em><strong>Happy Baking</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2007/02/28/getting-bake-to-work/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A to Z links with CakePHP</title>
		<link>http://www.flipflops.org/2007/01/31/a-to-z-links-with-cakephp/</link>
		<comments>http://www.flipflops.org/2007/01/31/a-to-z-links-with-cakephp/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 14:36:24 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Things]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2007/01/31/a-to-z-links-with-cakephp/</guid>
		<description><![CDATA[On a lot of websites, especially directories or those which contain large amounts of alphabetical data you see A to Z lists. You know the idea, click on a A and see every entry beginning with A, click on B&#8230; etc.
then&#8230;

Well, here is how to do it with Cake (a new PHP application development framework). It [...]]]></description>
			<content:encoded><![CDATA[<p>On a lot of websites, especially directories or those which contain large amounts of alphabetical data you see A to Z lists. You know the idea, click on a A and see every entry beginning with A, click on B&#8230; etc.<img src="http://www.flipflops.org/wp-content/uploads/2007/01/atoz.gif" alt="A to Z screenshot" /></p>
<p><strong><em>then&#8230;</em></strong></p>
<p><img src="http://www.flipflops.org/wp-content/uploads/2007/01/atoz2.gif" alt="A to Z list" /></p>
<p>Well, here is how to do it with <a href="http://www.cakephp.org">Cake</a> (a new PHP application development framework). It isn&#8217;t at all hard.</p>
<p>First some prerequisites:</p>
<ol>
<li>A working cake setup.</li>
<li>A simple model storing some data in the corresponding database table &#8211; in our case called Gallery.</li>
</ol>
<p><code><span class="syntax"></span><span class="syntax_alpha syntax_alpha_reservedWord">CREATE</span> <span class="syntax_alpha syntax_alpha_reservedWord">TABLE</span> <span class="syntax_quote syntax_quote_backtick">`gallery</span><span class="syntax_quote syntax_quote_backtick">`</span> <span class="syntax_punct syntax_punct_bracket_open_round">(</span> <span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></span></code><code><span class="syntax"></p>
<p class="syntax_indent1"><span class="syntax_quote syntax_quote_backtick">`id`</span> <span class="syntax_alpha syntax_alpha_columnType">int</span><span class="syntax_punct syntax_punct_bracket_open_round">(</span> <span class="syntax_digit syntax_digit_integer">10</span> <span class="syntax_punct syntax_punct_bracket_close_round">)</span> <span class="syntax_alpha syntax_alpha_columnAttrib">unsigned</span> <span class="syntax_alpha syntax_alpha_reservedWord">NOT</span> <span class="syntax_alpha syntax_alpha_reservedWord">NULL</span> <span class="syntax_alpha syntax_alpha_reservedWord">AUTO_INCREMENT</span> <span class="syntax_punct syntax_punct_listsep">,</span><br />
<span class="syntax_white syntax_white_newline"></span><span class="syntax_quote syntax_quote_backtick">`title`</span> <span class="syntax_alpha syntax_alpha_columnType">varchar</span><span class="syntax_punct syntax_punct_bracket_open_round">(</span> <span class="syntax_digit syntax_digit_integer">50</span> <span class="syntax_punct syntax_punct_bracket_close_round">)</span> <span class="syntax_alpha syntax_alpha_columnAttrib">default</span> <span class="syntax_alpha syntax_alpha_reservedWord">NULL</span> <span class="syntax_punct syntax_punct_listsep">,</span><br />
<span class="syntax_white syntax_white_newline"></span><span class="syntax_quote syntax_quote_backtick">`body`</span> <span class="syntax_alpha syntax_alpha_columnType">text</span><span class="syntax_punct syntax_punct_listsep">,</span><br />
<span class="syntax_white syntax_white_newline"></span><span class="syntax_quote syntax_quote_backtick">`created`</span> <span class="syntax_alpha syntax_alpha_columnType">datetime</span> <span class="syntax_alpha syntax_alpha_columnAttrib">default</span> <span class="syntax_alpha syntax_alpha_reservedWord">NULL</span> <span class="syntax_punct syntax_punct_listsep">,</span><br />
<span class="syntax_white syntax_white_newline"></span><span class="syntax_quote syntax_quote_backtick">`modified`</span> <span class="syntax_alpha syntax_alpha_columnType">datetime</span> <span class="syntax_alpha syntax_alpha_columnAttrib">default</span> <span class="syntax_alpha syntax_alpha_reservedWord">NULL</span> <span class="syntax_punct syntax_punct_listsep">,</span><br />
<span class="syntax_white syntax_white_newline"></span><span class="syntax_alpha syntax_alpha_reservedWord">PRIMARY</span> <span class="syntax_alpha syntax_alpha_reservedWord">KEY</span> <span class="syntax_punct syntax_punct_bracket_open_round">(</span> <span class="syntax_quote syntax_quote_backtick">`id`</span> <span class="syntax_punct syntax_punct_bracket_close_round">)</span></p>
<p><span class="syntax_punct syntax_punct_bracket_close_round">)</span></p>
<p><span class="syntax_punct syntax_punct_bracket_close_round"></span></p>
<p><span class="syntax_punct syntax_punct_bracket_close_round"></span></p>
<p></span></code></p>
<h3>Step 1 &#8211; edit the gallery controller</h3>
<p>You need to a new function to your gallery controller in order to show the A to Z link list. It should look something like this:<br />
<code></code><code></p>
<pre>function show($str = null ) {  if(!$str)   

   {   

    $this-&gt;set('str','');   

   }   

  else   

   {   

    $this-&gt;Gallery-&gt;recursive = 0;   

    $this-&gt;set('galleries', $this-&gt;Gallery-&gt;
                     findAll("LEFT(title, 1) = '$str'"));   

    $this-&gt;set('str',$str);   

   }   

     

 }</pre>
<p></code></p>
<h3>Step 2 &#8211; create the view</h3>
<p>You now need to create a view for this action, your view will should be called <em>show.thtml</em> and should be created in <em>app\views\galleries. </em>This is pretty simple &#8211; the only thing to take note of is right at the top -<strong> <a href="http://manual.cakephp.org/chapter/views">renderElement</a></strong><a href="http://manual.cakephp.org/chapter/views"> </a>- rather than put the code to write the A to Z list directly in the view, I&#8217;ve decided to create it in an element. This means that it can be reused in any view within the site.</p>
<p>The first parameter &#8216;<em>atoz</em>&#8216; is the name of the element which in this case will be called <em>atoz.thtml </em>the second parameter is an array containing the varibales that will be available to the element &#8211; <em>url</em> is the action we want the links to point to, <em>str</em> is the value of str we selected e.g. <em>b</em></p>
<p><code></p>
<pre>
&lt;?php   

   echo $this-&gt;renderElement('atoz', array('url' =&gt;
'/galleries/show/', 'str' =&gt; $str));   

?&gt;</pre>
<pre>&lt;?php</pre>
<pre>if(!empty($str))   

 {</pre>
<pre>?&gt;   

&lt;table cellpadding="0" cellspacing="0"&gt;</pre>
<pre>&lt;?php foreach ($galleries as $gallery): ?&gt;   

&lt;tr&gt;   

    

 &lt;td&gt;&lt;?php echo $gallery['Gallery']['title']; ?&gt;&lt;/td&gt;   

 &lt;td&gt;&lt;?php echo $gallery['Gallery']['body']; ?&gt;&lt;/td&gt;   

    

 &lt;td nowrap&gt;   

  &lt;?php echo $html-&gt;link('View',
      '/galleries/view/' . $gallery['Gallery']['id'])?&gt;   

 &lt;/td&gt;   

&lt;/tr&gt;   

&lt;?php endforeach; ?&gt;   

&lt;/table&gt;   

&lt;?php</pre>
<pre>
 }</pre>
<pre>?&gt;</pre>
<pre>
 </pre>
<p></code></p>
<h3>Step 3 &#8211; create the element</h3>
<p><code></p>
<pre>
&lt;?php</pre>
<pre> $alphabet = array('a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
 
 echo('&lt;ul class="atozlist"&gt;');
 $i = 1;
 foreach($alphabet as $link)
  {
   $class = '';
   if($i == 1)
    {
     $class = ' class="firstitem" ';
     $i++;
    }
    
   if(strtolower($str) == $link)
    {
      echo('&lt;li ' . $class . '&gt;
           &lt;span class="thisitem"&gt;' . $link . '&lt;/span&gt;&lt;/li&gt;');
    }
   else
    {
     echo('&lt;li ' . $class . '&gt;&lt;a href="' . $url . $link . '"&gt;
        ' . $link . '&lt;/a&gt;&lt;/li&gt;');
    }
  }
 echo('&lt;/ul&gt;');
?&gt;</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2007/01/31/a-to-z-links-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Fake Background Opacity</title>
		<link>http://www.flipflops.org/2006/12/12/how-to-fake-background-with-opacity/</link>
		<comments>http://www.flipflops.org/2006/12/12/how-to-fake-background-with-opacity/#comments</comments>
		<pubDate>Tue, 12 Dec 2006 19:07:15 +0000</pubDate>
		<dc:creator>Flipflops</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Things]]></category>

		<guid isPermaLink="false">http://www.flipflops.org/2006/12/14/how-to-fake-background-with-opacity/</guid>
		<description><![CDATA[The more observant among you will notice that the background of the website has changed recently. I love my butterflies but since I&#8217;ve been putting up a lot of pictures of art lately something had started to bug me.
The site is built with a simple centered container - I wanted the background of the website to [...]]]></description>
			<content:encoded><![CDATA[<p>The more observant among you will notice that the background of the website has changed recently. I love my butterflies but since I&#8217;ve been putting up a lot of pictures of art lately something had started to bug me.</p>
<p>The site is built with a simple centered container - I wanted the background of the website to show through but very faintly (at about 5-10% opacity). When you just have text this looks great, but as soon as you start to add photographs you start to run into problems &#8211; the background shows through the image &#8211; this is because the opacity effects everything within in.</p>
<p>For example if I have <strong>div id=&#8221;container&#8221;</strong> etc. with an opacity of 95% applied to it, all the child elements of that<strong>div</strong> will also have opacity of 95%&#8230;There is however a CSS solution &#8211; a trick &#8211; you need to create two background images and position them very carefully.</p>
<p><a href="/example/example1.html">Here are the detailed instructions and CSS</a>.</p>
<p> <a href="/example/example1.html"><img id="image93" height="100" alt="example 1" src="http://www.flipflops.org/wp-content/uploads/2006/12/example1.jpg" /></a> <a href="/example/example2.html"><img id="image94" height="100" alt="example 2" src="http://www.flipflops.org/wp-content/uploads/2006/12/example2.jpg" /></a> <a href="/example/example3.html"><img id="image95" height="100" alt="example3" src="http://www.flipflops.org/wp-content/uploads/2006/12/example3.jpg" /></a> <a href="/example/example4.html"><img id="image96" height="100" alt="example 4" src="http://www.flipflops.org/wp-content/uploads/2006/12/example4.jpg" /></a> <a href="/example/example5.html"><img id="image97" height="100" alt="example 5" src="http://www.flipflops.org/wp-content/uploads/2006/12/example5.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flipflops.org/2006/12/12/how-to-fake-background-with-opacity/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
