Archive for the 'Zend Framework' Category

Zend Framework Webinar - ZF Q&A Session

Posted April 30, 2008, 11:31am In: Zend Framework

The Zend Framework Webinar just finished. To be honest, I got to both nerd out and have some fun with it - including poking fun at the ZF team and Wil for dropping his mic.

There were a lot of topics discussed, including the future of Zend Framework, current challenges, and addressed concerns. They did let us know (I don’t subscribe to the Zend newsletter so I didn’t know this) that ZF has crossed the five million download mark, a jaw dropping number, as well as whispered some confirmation about integration with a third party javascript library. While I can postulate that the library will be either Dojo or jQuery (Dojo is used by a couple in the ZF team, and jQuery has critical mass), they pointed out (and re-iterated) that they don’t want to lock the community into one solution. If I want to use mooTools, YUI, etc, I’ll be able to. Cool.

Here’s what I got out of the webinar:

Be “just a wee bit more” Involved
There needs to be more visibility from the entire ZF team. Guys, let’s be honest, the person getting the most visibility right now is Matthew, and while I think he’s a splendid lad, there are more of you - I’m not saying that I don’t hear from Wil or Ralph or Darby, but I’d like to see more articles from you folks on DevZone and your particular blogs.

Go For More Community Involvement
There were a bunch of ideas tossed around, from building demo apps, open sourcing the code of the framework site (which isn’t going to happen any time soon, but they haven’t ruled it out) to having guest bloggers. Yes Wil, I will volunteer if needed =P. The problem that I addressed when I piped up is that projects like zfforums.com, despite having good intentions, don’t have the critical mass of users to make me prefer them to the mailing lists. And I hate email.

CLI Tools, With More On The Horizon
The challenge of developing CLI tools was addressed, and I translated this as “We’re working on it”. I wouldn’t mind a few code generation tools guys, that’s all I ask for. Creating all those blasted folders and files when I get a new project is sooo tedious.

The Future Is Bright and Shiny!
With talk about 2.0 (or 3.0 and 4.0, depending on who’s wise-cracks you listen to), Zend Framework Certification and lots of new code stuff - like Zend Framework Extras and scaffolding - the future looks bright indeed for the Zend Framework. There’s even talk about generating revenue!

Suffice it to say that I’ll be sticking with ZF, and blogging about it, for the foreseeable future.

There’s also more feedback via Joshteam’s Weblog.

Zend_Console_Process

Posted April 27, 2008, 9:11pm In: Zend Framework, PHP

Rarely do I get excited about a Zend proposal - and I definitely don’t post about the ones in progress on my blog. However, Zend_Console_Process deserves some attention.

If you’re at all familiar with pcntl this is for you. Pcntl allows you to control processes from within PHP (essentially allowing you to run threaded PHP code; fake “real” threading, at least). Zend_Console_Process is a Zend style interface to create threaded PHP applications in a usable manner.

If you take a gander at Ben’s first example, you’ll see the advantages:

Now, there’s been some interesting discussion on the mailing list already. For instance:

… Calling this “Threading” is a major misnomer. Threading would imply it has access to the same address space and descriptor table. That is not the case if this uses fork…

-Michael

Good point; so don’t take anything you read on the ZF site (actually, anywhere on the internet for that matter) as divine writ.

Like I said in my last post, it’s all about choosing the right technology. If you need to resize a couple dozen images, this will do you fine. If you need to build a video trans-coding server that can handle hundreds of videos at a time, well… perhaps it is time to choose a different language to do your heavy lifting. The fact that it doesn’t work on windows is a large hit to the adoption of Zend_Console_Process, but in my humble opinion, it is the most interesting proposal to come into review status since Zend_Service_Amazon_S3.

Building an audit engine with Zend Framework

Posted April 3, 2008, 7:53am In: Dragonfly R&D, Zend Framework

Part of what I love with ZF is the ease at which I can extend it to do what I need.

For instance, recently I was developing my app (codenamed Karmba) - something I needed to do is to be able to log every transaction, and at any time restore a version of information.

Let’s say for instance, that I have a blog - I know, I know, everyone uses that as an example, but let’s stick with something familiar, okay - and within my admin, I want to edit an entry. I start with my controller.

Disclaimer: This post is based on a real application, but isn’t all of the actual code. It is not plug and play; expecting this code to work out of the gate does not reflect what I’m trying to do.

For reference, DomainObject is just a convenience class - you can easily replace it with Zend_Db_Table

Now, let’s take a look at the Factory itself. A majority of this should be familiar to you.

Now, to illustrate my point, we create an object, Blog_Post - within Blog_Post there’s as much or as little as we need to alter the data.

Now this is where we start to see a little bit of the magic happen. Db_Table_Row (or another suitably named object) accesses functions that are called by Zend based on certain events. The event that I want to illustrate here is _postUpdate - an event that fires AFTER the object is updated. Now, a bit of hacking is required to get this to work. If you don’t know what _cleanData, _data or _modifiedFields are and how they’re used, a lot of this won’t make sense to you.

Now, inside AuditFactory is where we log all our transactions. We can revert entire objects or alternatively pick and choose what we update. That’s why every field gets a new object.

And that’s it!

This example proves how powerful the Zend_Db component of the Zend Framework is - and how contrary to popular belief - easy it is to extend existing functionality in a real world environment.

Audit factory doesn’t need to log to a database either. You could easily alter the class to the log entries to disk, or send an email, et cetera.

Feel free to comment, or expand on what I’ve said.

View Zend_Db_Select query

Posted March 31, 2008, 11:26am In: Zend Framework

Saw something in #zftalk that could be considered a no-brainer, but since the question was posed I’ll reproduce the answer here.

Rather than turning on the profiler to see what kind of query is being generated, use the __toString() magic method.

This should produce something like:

Drag & Drop Form Options with Zend Framework & Mootools

Posted January 31, 2008, 10:04am In: Zend Framework, SQL, Javascript, PHP

Recently I was working on a project that required the ability to define custom meta-data; this included categories and products, but also included a pre-determined list of countries and cities, etc.

Unfortunately, this hasn’t been tested on the latest version of the Zend Framework so it’s likely you’ll need to update your code accordingly.

We’re using version 1.2dev of MooTools

First, let’s create the controller:

I’ll skip the creation of fields and get right into the editing; I assume you’ve already added an index action and view. Our purpose is to effectively manage and modify field options, provide the ability to sort, edit and delete them, while preserving data related to the individual fields. For clarity, I will not use the view helpers for Form Elements.

Create your form and save it into your view, in my case edit-fields.php. I’ll leave it up to you to style and set form actions etc.

Then, pre-pend your javascript:

Now, before we get ahead of ourselves and worry about finding the fields, let’s the information and fields themselves - edit editFieldsAction() in your controller with the following:

Now let’s create our factory, in my case it’s MyFactory.php.

MyDomainObject::FetchCategory() validates that the requested categoryId exists. Then, the values assigned to that category. We could use $record->fetchValues() from within the rowClass instead of $obj->fetchValues($record->id), but it would more than likely just be an alias back to the factory.

Now, let’s open edit-fields.php again and add the following PHP between the UL.

An improvement to this would be to add an observer to all hyperlinks identified by class=”red”, but for simplicity, let’s leave that out. Now, our view should look something like this:

Assuming everything works, what should happen now is the list should pre-populate with previously created configuration options, we should be able to add, edit and delete those, and $_POST will override $this->options. Let’s start saving!

Edit editFieldsAction() to add some new functionality:

Now, back inside MyFactory:

It’s extra important that you pay attention to the usage of “ON DUPLICATE KEY UPDATE” - this is why we don’t have to do any fancy dancing. Additionally, we find the difference from $postArray versus what exists in the database to ensure that we delete anything that the user doesn’t want any more.

Additional steps might include the deletion of our user data when a config_value is deleted, either modifying the code itself or using the database.

Zend Framework 1.0.1

Posted July 31, 2007, 8:07am In: Zend Framework

A little late, but the Zend Framework got an update!

http://framework.zend.com/

Update your library!

Zend Framework and YAML config files

Posted July 13, 2007, 8:41am In: Zend Framework, PHP

Shahar has a post about using Zend_Config and YAML.

http://prematureoptimization.org/blog/archives/39/

Personal rant, and some goodies!

Posted February 28, 2007, 8:51am In: Zend Framework, Social Networking, Personal

Something I’ve been hearing a lot of lately is how companies and individuals want to set the standard. This can be a market standard, a development standard, or another business “standard” that they want to share with their fellow developers.

This seems a slight contradictory statement at times as “setting the bar” seems to be selective - for example, when it suits the interests of the individual rather than the company or the audience of the standard. This grows more and more confusing because in most cases with day to day development and business practice, most individuals I’ve had recent experience with aren’t really market experts at all.

Scenario:

Person A: Let’s ensure that we do this feature for this reason.
Person B: But why? It’s less accessible for the user, it isn’t going to optimize our development, et cetera. (and justifiable reason will do, just make sure you’re not arguing the point because you’re lazy).
Person A: Because that’s what the market trend is directed to accept.

If one is going to undertake such an ambitious venture as setting a new standard, or raising the bar so that competitors follow suit, don’t try to pick and choose which standards you’re going to enforce simply because they apply to your personal goals while relying on the “all powerful market” to justify other decisions. If you’re going to try to be the standard, BE the standard. In the case above, it was a pick-and-choose decision making process, and one I hope that doesn’t cascade through the rest of the company’s ventures.

In other news:

I’m quite the fan of this article, Top 18 Mistakes That Kill Startups. Definitely a must read.
Just a reminder that the Zend Framework 0.8 is out now - if you’re on the mailing list, you know that.

I’d like to thank (and by thank I mean through gritted teeth) Marco who has introduced me to another addictive site, Virb. It’s still in beta, but if you have an account, simply look me up (I’m the only Ryan Brooks that comes up in a search at the moment). I have to say, I’m quite impressed with it.

There’s another application called Ning which got itself an article on Techcrunch. Ning supposedly allows you to create social networking applications in minutes. I’ve seen applications like this over the years, and I hate to say it but I think this is yet another application that is going to fall short.

<3 __autoload

Posted February 21, 2007, 9:03am In: Zend Framework, PHP

When developing with the Zend Framework, it’s been my experience that the majority of our class files have a myriad of require statements before the class declaration. There are cases where these requires are not needed.

PHP 5.2.1 brings us all sorts of new goodies, one of them being the method spl_autoload_register(), part of the Standard PHP Library. When we tie this in with Zend::loadClass(), we can load our class files as needed.

Though there is some question about problems with application servers and things like bytecode caching, this gives us the added benefit of enforcing consistency in class naming - with consistency comes predictability, and saves us from having to RTFM, or double check our directory structure every time to find the proper file.

Though I am using this autoload method, I want to make sure that it is not slowing my applications down - there is quite some heated discussion on using auto-magical methods versus carefully crafted include statements. I’ll be paying very close attention to my dispatch times, and time will tell if I continue using this method.

Prototype + Zend = Good times

Posted January 18, 2007, 3:56pm In: Zend Framework, Javascript, PHP

So a quick update;

Prototype, the Javascript Library we know and love, has a new homepage at http://prototypejs.org/

And the Zend Framework has a brand new version out after last nights code freeze at http://framework.zend.com/