You're in the army now
Spec Ops
Special Operations. Specific posts about code and code libraries.
translate($this)
Nov 26th
So I needed to set up a translatable website and thought I would re-visit the way I use the translate component from the Zend framework. Previously I set up the translate component and would then create a plugin to handle the language change which I would trigger by changing a session variable.
Although this works I tended to feel it was a bit slap dash and that there must be a more efficient and useful way of utilising the component without the need to utilise a plugin.
So having had a nose around the net I decided that I wanted to make the language URL driven. I also wanted to steer away from using a subdomain to drive the language selection (i.e. en.website.com/pagename) and wanted it to be a part of the url (i.e. website.com/en/pagename) as this was more in keeping of the style of site I like to use.
So with a little tweaking code and utilising both the Locale, Translate and Router Resources here is how I did it.
More >
Zend In- Doctrine -ation
Nov 26th
So I’ve been using The framework and Zend_Db for a long tine now and I’m happy using it for some of the simpler projects I have had to do. However I have had a requirement to use an ORM.
I was looking forward to using the upcoming Entity component that was being built but after readingĀ this at nabble. I decided that it was time to investigate using Doctrine.
So after having a little play and reading all the tutorials/guides I could find I had a go @ integrating Doctrine into my latest project base.
So far no single guide/tutorial has gotten it 100% right for me. I was wanting to make it a seamless integration using the frameworks application component.
So here goes my amalgamation of quite a few guides to try and give a more complete picture. My apologies if I forget to attribute any bits of code I may have borrowed/adapted. Let me know and I will add you in.
Some things to make you aware of
- First I built this with 1.9.5 of the framework. I havent tried it with any earlier versions but it should work pretty much the same.
- I used Doctrine 1.2. It is still in beta on their website t the time of writing. But having had a nose through their blog I can see that they are on the verge of releasing it as stable. So by the time you read this it will most likely be stable. My reasoning for this is that 1.2 appears to handle the building of models a lot better than earlier versions.
- In order to get all the features I wanted to use working I had to adjust part of the Doctrine library. As part of the way I wanted to use doctrine was to build models automatically from yaml files. Unfortunately Doctrine appears to be reliant upon using a component from the symfony framework. Not that I’m knocking Symfony but I much prefer Zend and as such have no desire to use Symfony. That said.. for the sake of speed I downloaded Symfony and copied the 4 files I needed. I’ll cover what I didĀ bit later. I have logged this as a bug/task on Doctrines bug tracker (http://www.doctrine-project.org/jira/browse/DC-288) hopefully they will spot it and apply a suitable fix/inclusion.
- All my code is part of my own library which called Zucchi. All of my code is available in my project base in my subversion repository here. feel free to make use of it.
Getting squeakly clean with Zend_Soap
Sep 15th
I recently had to set up a SOAP service for a client. So I thought it was the perfect opportunity to get to grips with the Zend_Soap_Server.
Everything went swimmingly. I agreed on a structure with the customer and following the Zend Framework reference manual i managed to set up the server in no time at all using the auto discover feature.
Now I use a linux environment and tested the service with php_soap, nusoap and Zend_Soap_Client, and it all worked perfectly. it was so easy to use i found myself laughing.
But…. and here is the killer. Its only after I spent two whole days writing and testing the service that I hand it over to the customer and… it doesn’t work.
More >
Zend + TinyMCE
Jun 15th
EDIT: Since This article has been written the original code has taken down from our Subversion repository. to download a copy click here
In the course of my trying to do various things with the Zend Framework I am constantly haveing to create rich text editor fields.
Now the guys at Zend Framework have done a bang up job of of getting things started and the Dojo and jQuery libraries that are part of it are spectacular.. except that they dont offer an advanced text editor. Which I think is a bit of a shame. So I decided that In order to make my job a whole lot easier I would create a plugin that I could reuse as and when I needed it.
Please do bear in mind that this is not a completely finished plugin so feel free to fix the bits I miss. If you want to see/use my original code you can find it over at http://subversion.zucchi.co.uk.
So far This helper has allowed me to call the TinyMCE editor form countless views and forms.
Zend Lego – Initialise, Part 2
Mar 6th
In this part I am going to go through setting up some translation methods and setting up your database connection.
initTranslate()
Zend_translate provides us with a very powerful way of translating text in a website, I would strongly recommend reading the manual for more info on the full extensibility of the component.
I tend to use the GetText method of translation. Mainly due to its increased speed over other methods as it is a compiled source rather than plain text. If this sounds daunting then dont worry as there are a number of free applications that will help you to build the files you need… I use a combination of POEdit and the GTEditor Plugin for Eclipse. POEdit is by far the more powerful of the two as it will compile the relevant files for you as well as attempt auto translation. Gted only allws for the editing of the human readable source but I find it is a nice clean and intuitive interface.
So here is the code to throw into your Initialise class.
public function initTranslate()
{
$settings = Zend_Registry::get('settings');
if (Zend_Registry::isRegistered('Zend_Cache')) {
Zend_Translate::setCache(Zend_Registry::get('Zend_Cache'));
}
$options = $settings->translate->options->toArray();
$locale = Zend_Registry::get('Zend_Locale');
Zend_Registry::set('Zend_Translate',
new Zend_Translate('gettext',
$settings->translate->path ,
$locale->toString() ,
$options));
}

