Tag Archives: li3

Using ‘VC’ portion of ‘MVC’ in Zend Framework vs Lithium

Although I’ve been playing with Lithium for a few weeks, I haven’t needed to touch the view at all and barely looked at the Controller, so I didn’t really pay attention to this difference until just now…

In Zend, you set the vars in the controller for the view thusly.

Whereas in Lithium, you do it thusly.

Then in the view, to access those vars, here’s how Zend Framework does it.

With Lithium, if you use the same notation as the PHP short open tag, it will automatically escape the output. Which is great, although keep in mind that when you don’t want an htmlspecialchars escape, be sure to escape the var yourself as appropriate. Here’s the Lithium example.

I’m not sure how Zend Framework 2.0 will work yet. Been too busy to keep up to date.

I think the Lithium way is quite elegant. It’s a lot easier to explain to front end people who are mostly but not 100% in the view. There’s a variable, it’s the same in the controller and the view and you just access it.

It’s always good to check out different frameworks and learn what you can from each of them.

Aside: I love how people in the PHP community are for the most part really good about listening to the good and less good with an open mind and not making it personal. Matthew Weierophinney’s recent article about Filters and Nate Abele’s response is a classic example of the class acts in our community. I’ve learned much from all of you.

Setting up first Lithium project

I’m now starting my first Lithium project. So I thought I’d jot down notes while playing with it. Just random stuff. I’m not trying to accomplish anything in particular with this post. It might be interesting to you if you’re planning to try it out. Especially, if like me, you’re used to Zend Framework.

So far the docs are a little better than I expected, as we aren’t yet at release 1.0. But we should expect some speed bumps.

The first thing I noticed is the suggestion to install the whole framework under the docroot. To see the homepage you go to http://localhost/lithium . I’m sure that will change though so that your application code doesn’t live under your docroot. If you’re doing anything other than development, obviously you can and should fix this in production.

Something I like about the Zend Framework coding standards is the lack of an end php tag ?>. Having been bitten by that spacing after the endtag “bug” before, it now looks weird to me to see the end tag closing up a file. Hopefully #LI3 will follow Zend’s lead on that.

If you’d like to peruse the #LI3 coding standards, they are here. Overall I really like them.

Not sure what’s wrong with casting using shortcuts. Is it really ambiguous to say (int) $var rather than (integer) $var? (not a big deal in the scheme of things though)

Side note, I wish the PHP community would come to a consensus with the underscore thing before _protected methods.

I got used to it with Zend Framework. Now there’s a poll about removing it or not and last I looked it seemed that it was going away.

I just hope everyone keeps it…or removes it…but we make a community decision so that we don’t have another of these tabs vs spaces debates for the next 10 years. Which leads me to my next point. Kudos to #LI3 for choosing correctly with tabs ;) I thought I was in the minority about that. Certainly seems that way in the Open Source community.

One more thing. Just installed the Lithium Documentation Tool. This is so cool. Really excited to learn more.

I’m going to end this post with a little list of #LI3 RSS feeds that I started to follow. It may be updated periodically and do let me know if you know of any others:

http://nitschinger.at/

http://dev.lithify.me/lithium/wiki/blog.rss