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'»
Articles, PHP, Web Programming, Zend Framework, Zend_Auth, Zend_Auth_Adapter, Zend_Oauth, Zend_Oauth_Consumer
|
adapter, auth, authentication, oauth, PHP, twitter, zend, Zend Framework, Zend_Auth_Adapter_Interface, Zend_Auth_Result, Zend_Oauth_Consumer, Zend_Session, zf
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'»
Articles, PHP, Web Programming, Zend Framework, Zend_Oauth, Zend_Oauth_Consumer
|
application, authentication, authorization, framework, oauth, PHP, Sign in with twitter, token, twitter, zend, Zend Framework, Zend_Oauth, Zend_Oauth_Consumer
Summary
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'»
Computing, PHP, Web Programming, Zend Framework, Zend_View, Zend_View_Helper
|
class, framework, html, PHP, render, view, view helper, zend, Zend Framework, zend_view, Zend_View_Helper_Abstract
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'»
Articles, Certification, Computing, News about Work, PHP
|
5.3, beta, certification, exam, PHP, php 5.3, qualification, zce, zce 5.3, zend, zend certified engineer

Photo from http://www.flickr.com/photos/daniello/
Summary
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.
Motivation
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'»
PHP, Web Programming, Zend Framework, Zend_Registry, Zend_View_Helper
|
Body, framework, helper, html, PHP, view, view helper, zend, Zend Framework, Zend_Registry, Zend_View_Helper, Zend_View_Helper_Placeholder_Container_Standalone
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:
<?php
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….
<?php
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'»
Articles, Dependency Injection Container, PHP, Symfony, Zend Framework, Zend_Cache
|
cache, container, dependency injection, di, framework, ini, inversion of control, IOC, library, PHP, symfony, xml, yaml, zend, Zend Framework, Zend_Cache
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.
Articles, PHP, Web Programming, Zend Framework, Zend_Layout, Zend_View
|
application, framework, helper, PHP, view helper, zend, Zend Framework, zend_layout, zend_view
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'»
Articles, Computing, PHP, Web Programming, Zend Framework
|
action, controller, framework, helper, layout, module, PHP, zend, Zend Framework
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'»
Articles, PHP, Web Programming, Zend Framework, Zend_View, Zend_View_Helper
|
custom, framework, front controller, helper, PHP, Router, view, zend, Zend Framework, Zend_View_Helper_Abstract
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'»
PHP, Web Programming, Zend Framework
|
add, bootstrap, container, dynamically, Navigation, pages, PHP, sub-page, view, zend, Zend Framework, Zend_Navigation