The ArrayObject - adifferent approach to document containers

For Joomla! 3.x Coding related discussions, please use:

Moderator: ooffick

Forum rules
Please use the mailing list here: rather than this forum.
Joomla! Guru
Joomla! Guru
Posts: 527
Joined: Fri Aug 19, 2005 9:27 am

The ArrayObject - adifferent approach to document containers

Post by alwarren » Tue Mar 05, 2013 3:39 pm

I wasn't sure where to post this because it's more of an abstract idea than something that applies to a specific Joomla version. Call it a suggestion, an example, a new feature, whatever. So, mods, feel free to put this where you want.

When I say document containers, what I'm really talking about is all those arrays in the document model that store things like metas, scripts, css, etc.

About a year ago, I was working on a project using another framework. Being used to Joomla's document object, I wanted something that would mimick that. It needed all the typical containers - document type, language, title, css, scripts, etc. But what I also wanted was a way to prepend an item to a container. I tried various array handling techniques and somewhere along the way stumbled upon the ArrayObject. It wasn't so much the ArrayObject that caught my attention as it was what was missing - appending an item to the object. Fortunately, I found an example of how to do that. What I wound up with was a model where the containers were ArrayObjects instead of simple arrays. Plus, as objects, I can chain methods like this"

Code: Select all

And then somewhere along the way, maybe I need to prepend a script or css or meta for whatever reason. I can do this:

Code: Select all

Why would I make the title a container? Maybe I wanted to append something to it:

Code: Select all

$document->appendTitle(' : page 2');
Now I have "Site : page 2". But maybe along the way I want to prepend as well:

Code: Select all

$document->prependTitle('Company : ');
Now I have "Company : Site : page 2". Ok, maybe that's a little overboard but you get the idea.

So what does all this have to do with Joomla? First, I'd really like to see the ability to prepend items to some of the standard containers like scripts and css. I'd also like to see a container we can use just before the body close tag. Of course, method chaining is also a really nice feature.

Using a technique like this, we gain a lot of flexibility. Especially when it comes to extensions and how they interact with the document model and in particular how we render the head tag.

So, here's a link to the document container I used on that project:

Have a look, dig around, think about whether any of that stuff might work for Joomla. It was just an idea at the time and wound up hugely beneficial to my project.
Al Warren
This ain't my first rodeo. Red Foreman says it best.


Return to “Joomla! 3.x Coding”