PHP Frameworks

Here’s my very basic research into current PHP Frameworks – the target was to get this done in an hour.

Firstly if they have a professional design I’m assuming there’s at least a bit of funding behind the project.
Secondly I do a simple search for AJAX in their documentation. If they don’t mention how to use the framework with AJAX then I’m not interested.

Name PHP Version Professional Design Search AJAX in Help Worth further investigation
(CodeIgniter clone)
5 Yes No No – more CodeIgniter jobs about
Yii 5 Yes Yes Yes
(CakePHP clone)
5.3 Yes No No – more CakePHP jobs about
Akelos 4 Yes No  
PHP on Trax
(based on Ruby on Rails)
? Not really No  
Fuel 5.3 Yes No  
Agile Toolkit 5.3 Yes Yes  
CodeIgniter 5.1.6 Yes No Yes
CakePHP (V2) 5.2.9 Yes No Yes
Solar 5.2 Yes No  
Rain 5 Yes A little  
Recess 5.2.4 Yes No  

PHP Micro frameworks:

  • DooPHP
  • Fat-Free Framework
  • Limondae
  • Slim

I looked in detail at Agile toolkit but ultimately found their documentation too limited.
Recess looked good because of its focus on RESTful API which is built in – however I’m also keen on built in validation which this doesn’t have yet.

In summary for me it boils down to 2 factors, is it popular framework where jobs are advertised as requiring that knowledge and/or is it going to give a big advantage in developing applications rapidly. I’m going to focus my efforts on CakePHP (I’ve already built an app using 1.2.6 and version 2 will be launched very soon), CodeIgniter, Yii and also Fat-Free Framework.

Writing dynamic iframe content with JavaScript

I recently had the need to put a preview of some HTML in a page for a content management system. Simply inserting the HTML into the page wasn’t any good because it would then use the pages styling and so look nothing like how it would appear once live.

I could have set about making some large changes to the CSS so that the current styling only applied to content in one division, and in the preview area a totally different set of styles applied but that would have been time consuming.

The solution I came up with was to use an iframe tag which essentially is a brand new web browser window – and put the new content into ther

The first attempt was unsuccessful (code simplified):

<iframe src="javascript:void(0);">
<head><title></title><link href='/css/style.css' rel='stylesheet' type='text/css' /></head>
<body>preview content goes here</body>

Unfortunately that didn’t work out. As an iframe is the container for another html document you are meant to provide a location for that document via the src attribute. Content between the iframe tags is ignored if the browser supports the tag or displayed if the browser doesn’t recognise the iframe tag. The example above gives a ‘page not found’ message in a modern browser.

The way that did work in the end was using JavaScript, and it was suprisingly simple (no external libraries required).

write iframe tag (this time empty)
write a hidden form field containing the content – be sure to escape quotes " -> &#34;
run JavaScript immediately after form field is written, picking up its contents and writing these into the iframe

<input type='hidden' id='hidden1' value=\"<html><head><title></title><link href='/css/fckeditor.css' rel='stylesheet' type='text/css' /></head><body> content </body></html>
<script type='text/javascript'>mydoc = document.getElementById('content1').contentWindow.document; mydoc.write(document.getElementById('hidden1').value); mydoc.close();</script>

This works really well and solved my problems.

Is it a good idea to use a swap file on a cloud server?

ElasticHosts recommend: ‘You should configure your operating system without swap, using additional memory if necessary. This will significantly improve performance, since drives are provided over network RAID.’

I haven’t been brave enough to try this yet – but a brief bit of research showed that the following commands could be used.

#force the kernel not to use swap (default = 60)
sysctl vm.swappiness=0
#or  disable the swap file
swapoff -v /swapfile
# to confirm … show memory and swap usage
free -m

Using Windows Authentication with IIS Express 7.5

By default my installation of IIS Express (I think it was done through the Microsoft Web Platform Installer) had all the available authentication methods set to Deny.
When I first started using this I set anonymous and windows authentication to Allow as these were specified in the various web.config files of the applications I was working with.

However when it came to running a site that was using windows authentication, HttpContext.Current.User.Identity.Name was returning blank instead of a login name. It turns out that this is because anonymous authentication was being used in preference to windows authentication.

So, how can you change the configuration of IIS Express when there is no GUI to do this?
That’s easy – you just edit \My Documents\IISExpress\config\applicationhost.config
I struggled to find any documentation that describes how you can edit this though, specifically I just wanted to disable anonymous authentication for 1 particular site.

In the end I did the following:
In Visual Studio 2010, view the properties for the project (click the project, press F4) and set Windows Authentication: Enabled.
edit applicationhost.config – at the end of the document should be something like this:

<location path="YourSiteName">
               <windowsAuthentication enabled="true" />

Now add

<anonymousAuthentication enabled="false" />

in the authentication section, and that's it. IIS Express should now behave the way you want it to and you will be able to access user details obtained by windows authentication.

How to link a Flash movie to URL – tutorial

I spent ages on this a while ago and while there were some good tutorials out there – they missed off a few vital steps which had me stumped for ages. Here’s my attempt at a tutorial.

How to make a clickable Flash movie, clickable in the same way an image wrapped in an anchor tag is clickable – you click the Flash movie and your browser window gets taken to a new URL. Also I’ve developed this so the URL it navigates to can be taken from an HTML parameter so it doesn’t have to be hardcoded into the movie when you develop it.

This tutorial uses Adobe Flash Professional CS5.5 and in this instance I’ll work with a standard size advertising banner of 468x60px.

Start Flash Professional – it appears as shown below

Choose File / New from Template, Choose Advertising / 468 x 60 Full Size

The stage appears – create your advert (plenty of good tutorials on this so I won’t cover any further here, could be as simple as pasting 2 images and fading from one to the other)

Add a new layer on top of everything else you have done to hold the button which will detect and respond to any clicks from your visitors. I’ve named this layer ‘button’ in my example – select this layer.

Use the rectangle tool to draw a rectangle (colour doesn’t matter) of a size bigger than the canvas. This is going to be the button.

Right click the rectangle and choose Convert to symbol.

Choose Type of Button and click OK.

Double click the new button to edit it. You’ll see that the timeline has changed to show the button states of Up, Over, Down and Hit.

Drag the keyframe from Up to Hit – this has moved the coloured rectangle out of the visible part of the button and just made it the area that will respond to clicks, this is transparent so your banner advert will show through this.

Click Scene 1 to return to your movie and it should look like this.

Now we just need to add the ActionScript that will respond to the click, First we’ll set up the publishing settings of movie to use Flash 9 and ActionScript 2 – these are easier than using the later versions and may offer better compatibility. Click an empty part of the canvas and change the publish settings as shown in the right hand window as shown.

Click your button to select it and press F9 to view the ActionScript window.

Paste the following code into the window:

on (release) {
  if (_root.targetURL.substr(0,5) == "http:") {
  } else { 

This instructs Flash to get the URL to navigate to from an HTML parameter called targetURL that is defined along with the other parameters used to embed the Flash movie. If the code can’t find anything useful in there, it will fall back to a predefined URL.

Use getURL(_root.targetURL, “_blank”); if you want it to open in a new window, but this can be blocked by popup blockers so I would avoid this.

Now you need to publish the movie, which is simply selected from the File menu.

You are finished with Flash Professional now – the final job that remains is to edit the HTML to contain the URL that you want the movie to link to. You can either add this to the publishing code provided in the HTML file that Flash Professional will have created, or you can use SWFObject.

Default code created by Flash Professional

add the following once to each object tag

so the whole block will look like this

<div id="flashContent">
<object id="flash-test" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="468" height="60" align="middle">		<param name="movie" value="flash-test.swf" />		<param name="quality" value="high" />		<param name="bgcolor" value="#ffffff" />		<param name="play" value="true" />		<param name="loop" value="true" />		<param name="wmode" value="window" />		<param name="scale" value="showall" />		<param name="menu" value="true" />		<param name="devicefont" value="false" />		<param name="salign" />		<param name="allowScriptAccess" value="sameDomain" />		<param name="flashvars" value="targetURL=" />		<!--[if !IE]>-->		<object width="468" height="60" data="flash-test.swf" type="application/x-shockwave-flash">			<param name="movie" value="flash-test.swf" />			<param name="quality" value="high" />			<param name="bgcolor" value="#ffffff" />			<param name="play" value="true" />			<param name="loop" value="true" />			<param name="wmode" value="window" />			<param name="scale" value="showall" />			<param name="menu" value="true" />			<param name="devicefont" value="false" />			<param name="salign" />			<param name="allowScriptAccess" value="sameDomain" />			<param name="flashvars" value="targetURL=" />		<!--<![endif]-->			<a href="">				<img src="" alt="Get Adobe Flash player" />			</a>		<!--[if !IE]>-->		</object>

If you are using SWFObject then it should look like this

<script src="" type="text/javascript"><!--mce:0--></script>
<script type="text/javascript"><!--mce:1--></script>

Note that the clickable Flash movie will not navigate to a new URL when viewed in a browser locally – you have to view it from a webserver, something to do with web browsers security models.