Hi all!

For a bigger Joomla component I decided to stop writing duplicate code for every view, model and controller and created classes extending JView, JModel, JController and JTable. As an outcome, my controllers and models are each 5 lines long!

All you have to do is write a special JTable file. Instead of doing classic

var $tablefield;

you give some more meta information about that field, like 'type', 'validation', etc. See the screenshot for an example.


What are the advantages?

Automatic generation of lists and edit forms taking full advantage of almost all grid functions (Ordering, Checkin/Checkout/Locking, Published, pagination). Also, filters are generated automaticly, if you specify which field of your entity is a parent join you get subsequent filters until the root entity is reached. When changing a filter of a parent, child filters are automaticly reset.

For the edit forms: Depending on your field's type (e.g. boolean, text, textarea, htmlarea, join, number) your form is populated with appropriate form elements. Also, you have server and client-side validation. And optional tooltips for each field to explain the purpose.

As little bonus, you can define your fields as 'translatable', in that case you get an input element for each language installed in Joomla. That means that components like Joom!Fish only have to change your site language and you can say goodbye to creating content elements and even better, you have your content and translations right next to each other.

A coming feature will be finely-grained ACL, that hopefully work hand in hand with Joomla 1.6's ACL. The idea is that each field of your entity can be set to readable, writable for certain user groups.

So why am I talking about this? I want to make those libraries (6 files alltogether) freely available and license them under the MIT license. But I want to know if people are actually interested in this kind of library. So let me hear what you think!

PS: You find the files attached. They have to be included in the component's entry file


UPDATE: I attached a demo component (simple gallery component without frontend) to see the library in action.


libraries.zip

Views: 29

Comment by Júlio Pontes on September 28, 2009 at 2:52pm
Great! :)
Comment by Amy Stephen on September 28, 2009 at 3:44pm
Wow. :)

I'm also working on this problem but from a very different angle. I'll share more when it's ready.

This is very promising. Eager to hear what others think when they've looked at the code. (I've got a copy to play with, too!)

Martin - this is exactly the kind of sharing that makes community very powerful and I am grateful to you. Respect.
Comment by Oleg Nesterov on September 28, 2009 at 4:15pm
Hi. Not bad. I used my own "cheats" for such operations for a long time, but after discovering the Nooku Framework for Joomla I decided to use it instead of my own libraries. It has all and more than all I (and I suppose you too) need. Did you see it?
Comment by Gregory Daynes on September 28, 2009 at 4:16pm
Wow, I'm quite excited to try this out. I'll post my thoughts and findings when I've had a chance to test it.
Comment by Martin Rasser on September 29, 2009 at 5:21am
Thank you all for your positive feedback!

@Oleg: Yeah, I saw Nooku, but didn't actually dig into it yet. What don't like about it so far is the size and it seems like it replaces, not extends the Joomla framework. So in the end, your site might have an even bigger footprint on the server. I'll upload a demo extension on this post today or tomorrow, so that it's easier to see my lib in action.
Comment by Stian Didriksen on September 29, 2009 at 7:56am
Well, the size of Nooku is nothing compared to the code reduction you'll experience from using it: http://smashingdesign.net/koowa/

It does replace the joomla framework more than extending it, and that's why it works without noticeable overhead (my tests show a increase in performance, not decrease when the framework is running).

So my apologies, but bigger footprint on the server is speculation without real facts to back it up. You really should at least give it a try, or you'll fall seriously behind as using Koowa allow you to innovate, instead of like re-inwhenting the wheel all the time.

In the end, that's exactly what you are doing above, and I've done exactly the same as you above in our in-house framework. And I don't regret my move today. I now got time to do stuff like replacing table ordering with Mootools sortables and so much more I could never do before simply because I never had that extra time on my hands.
Comment by Martin Rasser on September 29, 2009 at 8:10am
Yeah, I'm certainly interested in Nooku. It's nice to hear that the framework makes Joomla components faster, according to the amount of files in the package and stuff in it, it really seemed to be big luggage.
Comment by Amy Stephen on September 29, 2009 at 3:09pm
Martin - also want to point out this discussion since I think both are getting at the same points of reuse and efficiency. Thanks!
Comment by Amy Stephen on September 29, 2009 at 6:03pm
Thanks for adding the gallery component example.
Comment by Amy Stephen on October 12, 2009 at 9:56pm
OK, Martin, I had some time to look more closely at your work.

First of all, you are absolutely heading in very good directions here. I am doing very similar things with a couple of differences that you might want to consider:

Moving your libraries folder into an actual library, loaded by a system plugin, starts to address the code reuse benefits - and ability to update that code with a single update to your plugin (assuming multiple components use it.) In case you haven't done a library before, you can use an old example of mine from the Tamka repository. I would do that. It starts to make your work more polished.

Also you need to get rid of those globals. Andrew Eddie has a good resource Converting Old Extensions to Joomla 1.5 . If you have questions, I went through this with my Tamka stuff, too, so I'd be glad to help if you need advice.

Then, I'd also recommend you look at Sam Moffatt's Packaging Manager - so that you can install the library with the Component(s).

This is exceptional work and it shows strong analytical skill.

Once you are done, I'd love to see your code laid out and compared to current Joomla! 1.5 core, like Nooku did.

My approach is like yours, with these additions, and it makes you feel REAL GOOD when you know, you aren't going to ever write that code again.

Very impressed and appreciate you sharing this.

Respect, Martin.

Comment

You need to be a member of All Together, As A Whole to add comments!

Join All Together, As A Whole

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service