Aug 25 2009

zce-test2

As some of you may know, back in March/April time, I started revising for my Zend PHP5 Certification, but that was pretty much put on hold when we had a baby… now I’m revising again and after having revised a couple of topics I retook the test. As you can see, I passed it “with flying colours” this time, but still have improvement to do with Streams and Design patterns…

Comparing with my last test:

  • 2 categories remained the same;
    • Database access
    • Web features)
  • 4 categories improved;
    • PHP 4/5 Differences (was FAIL)
    • Security (was PASS)
    • String Manipulation and Regular Expressions (was PASS)
    • Functions (was PASS)
  • 2 categories declined;
    • Streams and Network Programming (was PASS)
    • Design (was EXCELLENT) [eep - not so good that!]

I think overall however, these statistics shouldn’t be examined too much – there are some questions I can guess and don’t demonstrate that I truly *know* some topics, so I’m going to cover off a few categories I don’t feel to confident on anyway – but then the practise tests are just indicators, and not meant to represent the final exam… we’ll see!

May 16 2009

As with everything I do, I hack together solutions when there’s probably a much better and easier way of doing things. But anyway – if there’s not an easier way, then here’s a solution to my problem, and if there is, well… I’ll just use that in future…

My problem is that I want pretty URLs for my app, such as http://blah.com/home/folder/5/item/27. The URL structure of Zend Framework means that the URL has to look like this: http://blah.com/home/index/folder/5/item/27. There’s probably a way around that (my original idea was to use http://blah.com/home/?folder=5&item=27 but that’s just ugly), but I’ll settle for using the pointless verb “go” as the action name, resulting in http://blah.com/home/go/folder/5/item/27. But I also want that goAction to be called when I just go to http://blah.com/home/. I had a quick look at the ZF documentation, but I couldn’t see much about setting a default action in a controller, so here’s my solution:

class HomeController extends Zend_Controller_Action
{
	public function indexAction()
	{
		// ... action code here ...
	}
 
	public function goAction()
	{
		$this->_forward('index');
	}
}

As I said, there’s probably an easier way around this, but this works for me, so ner!

Update: As always, there is an easier way of doing this and I was reading the wrong part of the documentation. As Patrick says in his comment:

Hello, there is a way to specify default module, controller and action for each active route in the Zend_Controller_Router used by Zend_Controller_Front.

http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard.variable-defaults

just pass an array

Apr 10 2009

I’ve been getting to know Zend Framework, and despite it being awesome so far, there’s a few quirks I just don’t understand… maybe I missed something…

Anyway, David Cooper posted a quick howto on adding CSS to a Zend Framework page, which works and is all well and good, but there was a problem. The code that Zend Framework spits out was not XHTML valid. As I said, I might’ve missed something out, and this might be a really convoluted way of doing things, but give me a break, I’m just learning it!

Firstly, in your controller’s action (e.g. IndexController::indexAction), add a list of CSS files:

$css_files = array('index.css','test.css');
$this->getFrontController()->setParam('css',$css_files);

Modify the list of CSS files to suit your needs. Note that the $css_files must be an array, otherwise the helper class will ignore it. Now add a new PHP file in application/views/helpers called ‘CssInclude.php’, and put this in it:

<?php
 
class Zend_View_Helper_CssInclude
{
	function cssInclude()
	{
		$output = '';
		$fc = Zend_Controller_Front::getInstance();
		$baseUrl = $fc->getBaseUrl();
		$css_files = $fc->getParam('css');
 
		if(is_array($css_files))
		{
			foreach($css_files as $css_file)
			{
				$output .= '	<link rel="stylesheet" type="text/css" media="screen" href="';
				$output .= $baseUrl . '/css/' . $css_file . "\" />\n";
			}
		}
		return $output;
	}
}

This is a helper class that takes the parameter you set in the controller, and simply churns out an XHTML valid <link> tag. There’s just one more step, add this in your layout or view:

<?php echo $this->cssInclude(); ?>

And voila! If there’s a better way of doing this, then I’d like to know!

Apr 7 2009

UPDATE!!

For the new Zend Framework 1.8.x series, please refer to this article. This is still here for historical purposes.

This is a pretty simple howto, but here it is anyway!

I assume already that you’ve got a LAMP stack working, and if you don’t, it’s easy as pie to install one in Ubuntu:

sudo tasksel install lamp-server

So now you’ve got your LAMP stack up and running, lets download the latest SVN tag of Zend Framework. At the time of writing, the latest stable is 1.7.8, which I’ll use here. If you want to check for the latest version, visit http://framework.zend.com/svn/framework/standard/tags/ in your browser, and the last folder is the one you want. If you want stable full releases, ignore the RC/PR versions. So, once you’ve determined the version you want, we’ll check out the release:

cd /usr/share/php5
sudo mkdir ZendFramework
sudo svn co http://framework.zend.com/svn/framework/standard/tags/release-1.7.8/

It is likely you’ll need to use sudo for these commands as /usr/share/php5 is owned by root by default. You’ll see a big long list of files being checked out, and once that’s done you’ll have a new folder appropriately named “release-1.7.8″. Create a soft link called “current” to the release folder so you can change the default included Zend Framework version without restarting Apache in the future:

sudo ln -s release-1.7.8 current

You can stop there if you like, and manually add the include path into your PHP scripts using set_include_path. However, if you would like the current Zend Framework included automatically, then continue by opening /etc/php5/apache2/php.ini in your favourite editor. Add the path to your include_path list. For example, if your current include_path is (and this is the default):

include_path = ".:/usr/share/php5:/usr/share/pear"

Then change it to:

include_path = ".:/usr/share/php5:/usr/share/pear:/usr/share/php5/ZendFramework/current/library"

All you need to do now is restart Apache:

/etc/init.d/apache2 restart

In the future, if you wish to change to a new default Zend Framework version (for example 1.8.0), then just check out the SVN directory and change the soft link. You won’t even have to restart Apache, and the changes will take effect immediately! For example:

sudo svn co http://framework.zend.com/svn/framework/standard/tags/release-1.8.0/
sudo rm current
sudo ln -s release-1.8.0 current

If you want to keep up to date with the latest Zend software, then just subscribe to their RSS feed!

Feb 21 2009

zendserverconfigOK, so far all that I’ve managed to do is install it and have a dabble with the config pages and go “oooh that looks pretty”, so this isn’t a hardcore review or anything.

Zend have unveiled their newest product, Zend Server… which is essentially Zend’s own W/M/LAMP stack, but with Zend Framework and other components Zend have written, including the very handy Zend Debugger. What does that mean? Well to me, that means there’s quite an easy choice for my web development at home – I just installed it in 10 minutes and now have a fully working WAMP stack I can develop on before pushing to my Linode test server. It was 100 times easier than any other WAMP stack I’ve worked with including XAMPP and the other ones I’ve tried. It has a very shiny web GUI as well (pictured), that – as I mentioned before – I went “oooh” at lots. I personally think Zend Server has the potential to be really frickin’ awesome if I get to know it better. From the Public Beta Invitation e-mail, Zend states it includes:

  • Fully supported and certified distribution of PHP 5.2
  • Fully supported Zend Framework 1.7 release
  • Integrated native installers (RPM/DEB/MSI)
  • Web-based administration Interface
  • Comprehensive out-of-the-box database connectivity
  • Powerful PHP monitoring capabilities to identify problems and help fix them quickly
  • URL-based output caching required by today’s modern web applications
  • Zend Optimizer+ – byte code cache to boost application performance
  • New “Guard Loader” to enable processing of Zend Guard encoded files

Not bad – and there’s a community edition too, which means if you’re a sole developer like me it’s affordable.

<rant>Unfortunately, they don’t do a community edition of Zend Studio for Eclipse… and although PDT is good, I feel like its the hacky “well Zend Studio uses PDT at it’s core” alternative – without the cool enhancements that ZS has… oh well!</rant>