Archive for January, 2008

Zend Framework Manual is for 1.5PR not 1.0.3

Note that the online manual is for version 1.5PR, not 1.0.3. This is important as the new 1.5 features are now documented, but won’t work if you are using the 1.0.3 stable version of the Framework.

Also, as a side note, be aware that Zend_Loader is much slower in the 1.5PR release compared to 1.0.3, so don’t use it on a high traffic site! This issue has been fixed on the trunk (revision 7726), so if this issue is affecting you the give a snapshot a try and see if it solves it.

Posted by Rob on 31st January 2008 under News | Comments Off

Zend_Db_Table_Abstract in version 1.5

Zend_Db_Table has been significantly enhanced for version 1.5, mainly by Simon Mundy and is really really good. It's going to take me a while to poke around and find out all the new nuances!

However, I did find one gotcha that has affected me on my main project at work.

If you happen to have extended Zend_Db_Table_Abstract::_fetch() for some reason or another, be aware that it's changed in version 1.5.

It was:

PHP:
  1. /**
  2. * Support method for fetching rows.
  3. *
  4. * @param  string|array $where  OPTIONAL An SQL WHERE clause.
  5. * @param  string|array $order  OPTIONAL An SQL ORDER clause.
  6. * @param  int          $count  OPTIONAL An SQL LIMIT count.
  7. * @param  int          $offset OPTIONAL An SQL LIMIT offset.
  8. * @return array The row results, in FETCH_ASSOC mode.
  9. */
  10. protected function _fetch($where = null, $order = null, $count = null, $offset = null)
  11. {
  12.     // lots of stuff
  13. }


and is now:

PHP:
  1. /**
  2. * Support method for fetching rows.
  3. *
  4. * @param  Zend_Db_Table_Select $select  query options.
  5. * @return array An array containing the row results in FETCH_ASSOC mode.
  6. */
  7. protected function _fetch(Zend_Db_Table_Select $select)
  8. {
  9.     // much less stuff
  10. }


Just a heads-up in case someone else has customised this function for their own needs.

Related to this, Ralph Eggert recently discovered something else related 1.5 changes when extending Zend_Db_Table_Abstract and Simon Mundy helped out. The select object that is the parameter to _fetch() has a check in it to prevent you joining to another table. This is because if you join, you break the concept that a Zend_Db_Table represents a single table. However, you can get around it using the function setIntegrityCheck() like this:

PHP:
  1. protected function _fetch(Zend_Db_Table_Select $select)
  2. {
  3.     // extend select
  4.     $select->setIntegrityCheck(false);
  5.     $select->join(// do stuff);
  6. }


The setIntegrityCheck() statement allows you to do a join in the select object and very cleverly puts the table object into read only mode, which is great.

Also, Example 10.136 of the Zend_Db_Table documentation has more information on how to use the $select to get back the data you actually want.

Posted by Rob on 30th January 2008 under Tips and Tricks | 5 Comments »

Gotcha when using Zend_Form from the incubator

With my workload now getting a little more manageable, I can finally join Rob and keep this site full of useful updates and info. For my first, here is a small gotcha for those, like myself, who like to work on the occasionally painful cutting edge of Zend Framework development.

If you are have the incubator in your include path and are playing around with Zend_Form you may get something like the following error...

Zend_Form::__toString() must not throw an exception

...unless you remember to add the incubator view helper path in your controller like so:

$this->view->setHelperPath('/path/to/trunk/incubator/library/Zend/View/Helper/');

The reason being that Zend_Form has a few view helpers that it needs from the incubator.

Otherwise, you can avoid this issue entirely by just using the 1.5.0 Preview Release.

Posted by Nick on 30th January 2008 under Tips and Tricks | Comments Off

Zend Framework 1.5 Preview Release

Darby has just announced the availability of 1.5 Preview Release!

This is a great time to download it and check out the new features.

From Darby's post, the main new features are:

  • New Zend_Form component with support for AJAX-enabled form elements
  • New action and view helpers for automating and facilitating AJAX requests and alternate response formats
  • Infocard, OpenID, and LDAP authentication adapters
  • Support for complex Lucene searches, including fuzzy, date-range, and wildcard queries
  • Support for Lucene 2.1 index file format
  • Partial, Placeholder, Action, and Header view helpers for advanced view composition and rendering
  • New Zend_Layout component for automating and facilitating site layouts
  • UTF-8 support for PDF documents
  • New Technorati, SlideShare, and Remember the Milk web services

Also, many of the other components have been improved.

Posted by Rob on 29th January 2008 under News | 1 Comment »

Zend Framework Help

When you are in need of help with the Zend Framework, these are some places that I go:

If you want to discuss ZF in real time and maybe get a question or two answered, then join the IRC channel #zftalk on freenode.

There are also forums at http://www.zfforums.com/ but I've never used them. Worth checking out though if webfora is your media of choice.

Where else do you go for ZF help and discussion?

Posted by Rob on 28th January 2008 under Around the web | 5 Comments »

Difference between two dates

In response to a mailing list question, Thomas, the lead developer of the I18n components pointed out that to find the difference between two Zend_Dates, you just have to subtract them:

PHP:
  1. $date = Zend_Date::now();
  2. $diff = $date->sub($birthdate);
  3. $diff->toString();


Useful tip, that I've put here mainly so that I can find it again when I need it!

Posted by Rob on 27th January 2008 under Tips and Tricks | 4 Comments »

Zend_Filter_StripNewlines Proposal

Martin Hujer has prepared a Zend_Filter_StripNewlines proposal along with prototype code (and tests).

This is a very simple filter that does what it says on the tin: removes all new line characters from a string and resolves issue ZF-2427.

In general I'm all for a rich set of filters and validators as you never know what you are going to need for a given project.

Posted by Rob on 26th January 2008 under News | 2 Comments »

ZF Packaging for 1.5

In a couple of recent posts, Wil Sinclair has outlined some changes related to the packaging and distribution of the Zend Framework for version 1.5.

Extras
Extras are components that are developed under the ZF community process (i.e. CLA, unit tested, documented, coding standards, etc.) but are not supported commercially by Zend Technologies. From Wil's post on it:

The distinction between components chosen for core incubator and those chosen for extras incubator is simple: Zend will provide support for components in core- but not extras- while providing distribution for both core and extras on the main ZF site... ...The strict guidelines for quality that we have enforced for core components, such as test code coverage and documentation, would also apply to components in extras.

I think that this is a good idea as the community will be able to provide components that Zend may not be interested in supporting, but are very useful. I expect various Zend_Service_ components to end up here and with any luck, Zend_Db_Adapter_Pdo_Odbc_Mssql!

Lean and Mean
In a separate post, Wil also indicated that version 1.5 of the Zend Framework will be distributed in two forms:

  • "Lean and Mean"
  • "Everything"

The "Lean and Mean" package will include just the core framework, excluding locale files.

The "Everything" package will contain everything(!) including unit tests, demos, locale files and the extras directory.

This should make the core download for ZF much smaller which is great for those of who don't need the files in "Everything".

All we need now is for someone to step up and make a PEAR channel for the Framework...

Posted by Rob on 26th January 2008 under News | 2 Comments »

UK PHP Conference

The UK PHP Conference is a one day event on the 29th February 2008 and I'm speaking with Toby Beresford and Ian Christian about three PHP frameworks: Zend Framework, Symfony and CodeIgniter. You should go!

There's a lot of great talks and I'm slightly miffed that I'm going to miss Zoe's talk on testing PHP, so I really hope that the someone takes notes for me ;)

The general plan is that we discuss each of the three frameworks in turn and then have a Q&A round-table type thing where we can compare and contrast the frameworks together. Obviously I'm talking about the Zend Framework and I want to talk about the key features about the Framework.

I'm not a "them vs us" type of person and so I'm not into bashing other frameworks, especially as I think that using any framework improves the productivity of most developers. However I do want to help emphasize the features of ZF that make it different.

One thing about the Zend Framework is that its scope is vast!

I thought, I'd start by brainstorming about which feature was the one that made you decide to investigate it more? For me, it was actually Zend_Search_Lucene that piqued my interest. I was struggling sorting out a better search system for one of our clients when I first heard about the Zend Framework, so it hit home that maybe that would be a better solution going forward. Since then, I'm now enamoured by the MVC system's flexibility. Whenever I've needed to change something, I've found that there's a flex point where I need it. Now that we are using the Framework in production sites, we're finding the other features useful too.

So... what you think I need to cover to help people understand the strengths and weaknesses of ZF?

Posted by Rob on 23rd January 2008 under News | 7 Comments »

Zend_View article at KillerPHP

The guys over at KillerPHP have posted a new article called Zend Framework Components Part 2: Zend_View.

As you can guess, it's about Zend_View and goes how to create a Front Controller plugin that will automatically add a header and footer template to all your pages.

This is really useful if you are using Zend Framework 1.0.x, but don't forget that Zend_Layout is coming for 1.5.

Posted by Rob on 15th January 2008 under The Book | Comments Off

Next »