You're in the army now
Posts tagged locale
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 Lego – Initialise, Part 1
Feb 12th
So we have managed to get a basic starting point for the application. Its time to now load everything that we are going to be using into it.
If you want to get a complete example of the Initialise class that i’m going to be talking about you can view it at http://code.google.com/p/zucchi-titan/source/browse/trunk/application/Initialise.php.
So the first thing to address is the reasons for this being a plugin. The main reason is because the Zend Frameworks plugin structure allows us to trigger off different things at set intervals in the applications loading/closing.
The primary functions we will need make use of the plugins capabilities are
public function __construct()
public function routeStartup()
public function routeShutdown()
public function dispatchLoopStartup()
public function preDispatch()
public function postDispatch()
public function dispatchLoopShutdown()
These are loaded in the order they are listed here. We will go through the structure of plugins in more depth at a later date.
So we start with our constructor. Here we load anything that is needed throughout the entire site an dnot just at set intervals.
In the original Zend Lego post we called instantiated the class with
$frontController->registerPlugin(new Initialise(APPLICATION_ENVIRONMENT));
The first thing to handle is the APPLICATION_ENVIRONMENT constant. Inside the class we will assign this to the variable $_env. so that we can refer back to it when needed.
We then will want to set a session so that we can make use of that across the application. I’ll cover this a little bit later.
The next thing is to get a reference to the Front Controller so that we can set that up to do waht we need it to. We can get this by using a static call to the front controllers ::getInstance() method like so
$this->_front = Zend_Controller_Front::getInstance()
Using the static method means that we keep to a singleton pattern and don’t accidentally set a second front controller.
We then get into calling a bunch of custom methods to set up specific items. More >

