Christian Schaefer’s Blog: Using Zend Framework components in a Symfony2 project
Feb 28, 2011 php, Zend Framework
On his Test.ical.ly blog Christian Schaefer has a new post looking at how you can use Zend Framework components in a Symfony2 application.
Recently I wanted to use a part of the Zend Framework (v1) in my Symfony2 project. After struggeling with the autoloading for a while and a little help from fellow developers on Twitter I found it actually to be quite easy.
He illustrates, showing a method for pulling down the source from github, registering a prefix with Symfony2 for the Zend Framework components and how to remove a lot of the issues with notices and warnings (and fatal errors) by removing the require_onces that aren’t needed.
Tags: php, zend framework
PHPUK 2011 Talk: Beyond Frameworks – Stuart Herbert
Feb 25, 2011 php, Zend Framework
I’ve just finished giving my talk at this year’s excellent PHP UK 2011 conference, on how to use code frameworks like Zend Framework and Symfo
Tags: frameworks, hostage, php, slides, stuart herbert, Top stories, zend framework
Six ways to be a better client for your developer – Point 8
Feb 22, 2011 php, Zend Framework
Dear Reader, [Note from the author:Yes, I know we are way past six points now but things keep popping up around this topic that I feel need to be pointed out.] Point 1 – Understand that you alone know the problem Point 2 – Understand that they probably know the best solution Point 3 – [...]
Tags: Intellectual Property, license, php, Programming, web development, zend framework
Zend Developer Zone: ZendCon Sessions Episode 38: Reusable Bootstrap Resources with Zend_Application
Feb 21, 2011 php, Zend Framework
New on the Zend Developer Zone today is the latest podcast in their “ZendCon Sessions” series (as recorded at the Zend/PHP Conference 2010 in Santa Clara, CA). In this episode Hector Virgen talks about creating reusable bootstrap resources with the Zend_Application component of the Zend Framework.
His talk introduces you to bootstrapping, shows how to get started with Zend_Tool and shares code and configuration details for using resources in your controllers.
You can listen to this latest episode either through the in-page player, by downloading the mp3 or by subscribing to one of their feeds. The slides are also on Slideshare if you’d like to follow along.
Tags: php, zend framework
Zend Developer Zone: Announcing the February 2011 Zend Framework Bug-Hunt
Feb 17, 2011 php, Zend Framework
In a new post to the Zend Developer Zone, Ralph Schindler has posted about this month’s Bug Hunt Days for the Zend Framework. They start today (Thursday, February 17) and run through Saturday.
For those who haven’t put the reoccurring event in their calendar, this announcement is for you: Zend Framework Monthly Bug-hunt is here again! This Thursday, Friday and Saturday of February (the 17th, 18th and 19th 2011), we’ll be hosting our monthly bug hunt. For those of you unfamiliar with the event, each month, we organize the community to help reduce the number of open issues reported against the framework.
Last month the event closed 24 issues with a tie for first. If you’re wanting to get involved and close even more of those issues, the post has the steps you’ll need (including filing a CLA with Zend).
Tags: php, zend framework
Stefan Koopmanschap’s Blog: Would you like docs with that?
Feb 16, 2011 php, Zend Framework
Stefan Koopmanschap has a quick new post to his blog today talking about a webinar he and Zend will be putting on this Thursday (Feb 15th) about why documentation should be an important part of your development practices.
Tags: benchmarking, development practices, php, Top stories, webinar series, webinars, zend framework
Rob Allen’s Blog: Using your own View object with Zend_Application
Feb 16, 2011 php, Zend Framework
In the latest post to his blog Rob Allen shows you how to create a custom View object for your Zend Framework application with the help of the Zend_Application component. It uses one of two ways to set up this custom view object – either in the bootstrap or as a custom resource.
Let’s say that you want to use your own view object within your Zend Framework application. Creating the view object is easy enough in library/App/View.php along with adding the App_ namespace to the the autoloader in application.ini. All we need to now is get Zend_Application to bootstrap with our new view class. There are two ways of doing this: within Bootstrap.php or using a custom resource.
He includes the code to make it happen both ways – by adding an _initView method in the application’s Bootstrap.php file or by creating a new class called App_Resource_View that overrides the getView() method that grabs the custom object.
Tags: php, zend framework
Using your own View object with Zend_Application
Feb 16, 2011 php, Zend Framework
Let’s say that you want to use your own view object within your Zend Framework application.
Creating the view object is easy enough in library/App/View.php:
class App_View extends Zend_View
{
// custom methods here
}
along with adding the App_ namespace to the the autoloader in application.ini:
autoloadernamespaces[] = "App_"
All we need to now is get Zend_Application to bootstrap with our new view class. There are two ways of doing this: within Bootstrap.php or using a custom resource.
_initView() in Bootstrap.php
At first blush, the code looks quite easy. In application/Bootstrap.php, we add our own method that creates the view object and assigns it to the viewRenderer:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
$view = new App_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
return $view;
}
}
As we have named the method _initView(), our method will take precedence over the built in View resource and be used instead. However, this implementation will ignore any view options that are configured in application.ini using the resources.view key, so a better method is this:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
$resources = $this->getOption('resources');
$options = array();
if (isset($resources['view'])) {
$options = $resources['view'];
}
$view = new App_View($options);
if (isset($options['doctype'])) {
$view->doctype()->setDoctype(strtoupper($options['doctype']));
if (isset($options['charset']) && $view->doctype()->isHtml5()) {
$view->headMeta()->setCharset($options['charset']);
}
}
if (isset($options['contentType'])) {
$view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
}
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
return $view;
}
}
This version takes into account your configuration settings and behaves the same as the View resource provided by Zend Framework. The only difference is that we’re now using App_View.
Custom resource
Another option is to override Zend_Application_Resource_View with our own view resource. In this case, we create a class called App_Resource_View stored in library/App/Resource/View.php. We only need to override one method, getView():
class App_Resource_View extends Zend_Application_Resource_View
{
public function getView()
{
if (null === $this->_view) {
$options = $this->getOptions();
$this->_view = new App_View($options);
if (isset($options['doctype'])) {
$this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
$this->_view->headMeta()->setCharset($options['charset']);
}
}
if (isset($options['contentType'])) {
$this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
}
}
return $this->_view;
}
}
Essentially, all I have done is replace the class of the view object to be App_View and left everything else alone so that it behaves the same as the default View resource.
To get Zend_Application to load our custom resource, we just add one line to application.ini:
pluginPaths.App_Resource = "App/Resource"
We now have a reusable resource that will load our own View class and can easily take it from project to project.
Tags: php, zend framework
Announcing the February 2011 Zend Framework Bug-Hunt – Zend Deve…
Feb 16, 2011 php, Zend Framework
For those who haven’t put the reoccurring event in their calendar, this announcement is for you: Zend Framework Monthly Bug-hunt is here again! This Thursday , Friday and Saturday of February (the 17th , 18th and 19th 2010 ), we’ll be hosting our monthly bug hunt. For those of you unfamiliar with the event, each month, we organize the community to help reduce the number of open issues reported against the framework.
Tags: bug hunt, php, Top stories, zend framework
Zachary Burnham’s Blog: Code: Setting up unit testing in Zend Framework with multiple databases
Feb 11, 2011 php, Zend Framework
Zachary Burnham has a new post to his blog looking at his technique for unit testing multiple databases in a Zend Framework application.
As part of this project, I’m required to work with two separate databases; the osCommerce database and a new database to track barcodes on the coupons. I found myself needing to rewrite the purchase rules that we’d created in osCommerce in a ZF model. The rules are complex, compounded by the fact that we can’t use the customer IDs in osCommerce, we’re only able to use the customer’s utility account number, as well as the fact that the purchase rules limit purchases by category and not product, and a product can be in multiple categories… well, you get the idea.
He includes a relevant bit from his application.ini to show the database setup and the code for a base testing class (originally from Matthew Turland) to work with the databases. He had an issue where he was getting bad “not found” errors when trying to load the classes in the tests, but eventually figured out that it was the framework not being bootstrapped that was causing the problem. He shows his modified phpunit.xml configuration and has a sample test to show how it all ties together.
Tags: php, zend framework

