Posts tagged: PHP

Oauth / Twitter Auth Adapter for Zend Framework

By , Saturday 23rd April 2011 3:57 pm

Work continues (slowly) on my new Twitter-based application. Over the next couple of bank holidays I hope to get the momentum going again on the project (in-spite of the wonderful weather at present). Anyway, my next task was to create an authentication adapter for the Zend Framework. I had a working login implementation, but having a drop in Auth adapter for Zend Framework seemed like an attractive proposal, so I created it….

(I’m not going to go through Oauth or registering your application with twitter, there’s hundreds of guides and its a fairly straightforward process anyhow.)
Continue reading 'Oauth / Twitter Auth Adapter for Zend Framework'»

“Sign in with Twitter” using Zend Framework

By , Thursday 17th March 2011 1:07 am

Despite all the twitter hate at the moment, I’ve set out to create a new twitter-based application. Being someone who manages several accounts (both personal and for my charity work) I’ve been needing a tool for sometime that I’m just getting around to writing (more of that in the near future…).

I’ve read up on Zend_Oauth_Consumer and how it can be used to get authorisation for interacting with twitter using oauth. All well and good, I have my access key and I can merrily post away on a user’s behalf. There’s plenty of resources out there to do this so I won’t bore people.

The next step was to allow people to return to the website, log in and modify their account. This is where I reached a slight problem. Using the code examples on websites meant that I’d have twitter asking me for access authorisation again for each login, not good. Scanning through the framework I couldn’t see anything which would allow me to just request authentication. That isn’t to say its not there, but there didn’t seem to be an authentication mechanism that could be invoked without knowing the access token already.

The alternatives were to implement a site-based log in or somehow store the user’s access token on the client (encrypted of course). Neither of these seemed like a good/suitable solution.

Continue reading '“Sign in with Twitter” using Zend Framework'»

Zend Framework: Render If Exists

By , Sunday 12th December 2010 4:19 pm


This is a quick post to discuss the rather simple view helper I created for rendering a Zend Framework style view file only if it exists. Generally asking the code to render a file which doesn’t exist will throw an exception. Therefore I created a wrapper for the Zend_View::render() method which determined whether the file exists and if so renders, otherwise simply returns an empty string.
Continue reading 'Zend Framework: Render If Exists'»

Zend Certified Engineer (ZCE) 5.3

By , Thursday 30th September 2010 9:00 pm

With the official release of the Zend Certified Engineer (ZCE) programme for 5.3 I thought I’d give  my quick impression of what I thought of the exam.

A little background on myself: I was first introduced to PHP about 7 years ago and have worked professionally in PHP since 2006. I currently work for an exciting start-up called Brightpearl based in Bristol, UK, producing integrated CRM, accountancy, and ecommerce software. I haven’t previously obtained any of the previous ZCE qualifications. I currently develop in the 5.2.X series and haven’t really used any of the specific 5.3 features (I’m waiting for Zend Framework 2 and Doctrine 2) in my development projects.
Continue reading 'Zend Certified Engineer (ZCE) 5.3'»

Zend Framework Body Tag View Helper

By , Saturday 21st August 2010 11:13 pm
Photo from

Photo from


Here I discuss the creation of a view helper for modifying HTML tags, and more specifically body tags. The created view helper allows functionality similar to the head*/inlineScript view helpers already in the standard Zend Framework view helpers, but allows the programmatic modification of tag attributes. Definitely check out the demo page and the code on github.


The standard Zend Framework view helpers are a great set of tools for streamlining mundane view tasks and allowing for the modification/addition of scripts and header blocks (generally held in the layout) from within the view without applying ugly hacks (i.e. the head*/inlineScript view helpers).

Upon occasion I have found need to make modifications to the <body> tag, for example adding an onload, class, or style attribute etc. I also required to be able to perform this from within other view helpers. Take this following contrived example…

On website X, certain pages include standard dojo forms. These dojo forms are held within view helpers for convenience. Generally it has been decided not to include the dojo CSS classes in the body tag and only add them when necessary. There maybe several view helpers on the page that need to add their own attributes to the body tag. (I said it was contrived)

The code is available in my GIT repository @ github and the demo page.
Continue reading 'Zend Framework Body Tag View Helper'»

Quick Start Symfony DI (Dependency Injection) Tutorial

By , Saturday 14th August 2010 2:21 pm

What is Dependency Injection (DI)?

Dependency injection is a technique that allows for loosely coupled objects within a software application. Generally if an object requires access to the functionality of another it would be instantiated internally leading to tightly coupled systems. By implementing dependency injection we inject the required objects ready for use (sometimes also referred to inversion of control – IOC). Take the following example:

class DecisionMaker {
    public function makeDecision(array $parameters) {
        // Need the database adapter
        $dp = new DecisionParameters();
        $parameterScore = $dp->getScore($parameters);
        /* ... Some more decision logic ... */
        return ($parameterScore > 50);

This piece of code is said to be tightly coupled to the DecisionParameters object. Rewriting the above in a loosely coupled fashion we’d have something like….

class DecisionMaker {
    private $_dp;
    public function __construct($dp) {
        $this->_dp = $dp;
    public function makeDecision(array $parameters) {
        $parameterScore = $this->_dp->getScore($parameters);
        /* ... Some more decision logic ... */
        return ($parameterScore > 50);

Whilst gaining the benefits of loosely coupled code we are adding complexity such that each time an object is instantiated we also have to instantiate its dependencies and pass these in too. For example, this:

$choice = new DecisionMaker();
echo $choice->makeDecision(array('effort' => 'low', 'return' => 'high'));

now becomes:

$dp = new DecisionParameters();
$choice = new DecisionMaker($dp);
echo $choice->makeDecision(array('effort' => 'low', 'return' => 'high'));

This situation becomes more painful as the number of dependencies for a class is increased, and what if the dependencies themselves have dependencies? This can quite quickly become an object administration nightmare! Enter dependency injection containers (or frameworks)…
Continue reading 'Quick Start Symfony DI (Dependency Injection) Tutorial'»

Naked Zend_Layout and Zend_View

By , Tuesday 10th August 2010 11:47 pm

In this article I look at using Zend_Layout and Zend_View along with a simple front controller to show how it is possible to start separating business logic and presentation within your application. All code is available on github:
Naked Zend_Layout and Zend_View on GitHub.

Continue reading 'Naked Zend_Layout and Zend_View'»

Zend Framework Per Module Layout Settings – Follow Up

By , Tuesday 16th February 2010 8:48 pm

As a follow up to my previous post on per module based layout settings for Zend Framework, I’ve updated the code to require less configuration then before (not that it required more that a few lines in your application configuration!).
Continue reading 'Zend Framework Per Module Layout Settings – Follow Up'»

Creating URL in Zend Custom View Helper

By , Thursday 28th January 2010 11:01 pm

This may seem simple, but I was banging my head trying to create a URL in a custom view helper in Zend Framework. I have routing setup which gets the module from the sub-domain in use so I couldn’t use a simple hardcoded URL.

Continue reading 'Creating URL in Zend Custom View Helper'»

Dynamically add pages to Zend_Navigation container at runtime

By , Thursday 7th January 2010 10:50 pm

In a continuation on my last post about Zend_Navigation, Route requests for sitemap.xml to custom controller/action, this post is about dymnamically adding pages to a Zend_Navigation container at runtime/script execution.

Its all well and good specifying your pages in a ini or xml file but at some point you’re going to have changing pages in your site that you want as part of a menu, sitemap, or to be included in your breadcrumb trail. Therefore what we need to do is add pages to our Zend_Navigation container at runtime. Examples for this would be in adding news items, blog posts, or page comments, etc.

Continue reading 'Dynamically add pages to Zend_Navigation container at runtime'»

Panorama Theme by Themocracy

5 visitors online now
4 guests, 1 bots, 0 members
Max visitors today: 8 at 07:11 am UTC
This month: 15 at 12-11-2017 04:06 pm UTC
This year: 45 at 02-01-2017 10:28 pm UTC
All time: 130 at 28-03-2011 10:40 pm UTC