views:

41

answers:

2

I'm working on a small website and need to display blocks of static text on the front page. These blocks will be styled later as paragraphs or bullets and so on.

Where do you suggest I store this text? Do they go as variable in each view where they are used? I could do that, but I'd prefer to have a central location for all this text.

At the moment, the site is very small and hasn't needed to be database driven but that will likely change so I don't mind using the database for storage if that's a better practice. Though I think storing in the database will make it harder to edit the text from my IDE.

I'm guessing the MVC structure Zend uses thought of a solution for this already

+2  A: 

If your blocks of static text will be always the same and there won't be any new texts generated dynamically, then you could make use of partials in Zend.

store all of your little texts as partials. In your view script you'll have:

echo $this->partial('partial01.phtml',array('somedata'=>'if you need it'));

You just need to have the partial01.phtml file and any other you need in the views/scripts directory.

Slavic
What if the content is a list of small sentences. It wouldn't make sense to create a partial for each sentence. I still want to keep each sentence separate so I can style it differently, as a bullet point or something else. In other words, I don't want the partial to contain markup, so I can control the markup in the main file.
dave
I'd go with a database in this case.
Slavic
+3  A: 

Sounds like the key points are:

  1. to have all the data in a raw atomic, un-styled format
  2. stored on the filesystem so that you can easily edit via IDE.

So, maybe an XML file? It can optionally assign id to each atomic text-chunk. Then you can write a class that reads the XML file and offers an interface like getAll(), getById($id). This gets you the raw data which you can then style however you want - into a bunch of <p>'s, <li>'s, etc.

SimpleXML is pretty easy to work with.

David Weinraub
I like the getById idea.. As to the XML, which would be faster to retrieve, storing in XML or storing in database?
dave
For small datasets, I'd guess XML since it resides in the filesystem, no network latency. The downside is that you have to parse the whole file. A db with proper indexing would probably be better for pulling individual items using getById(), especially with a larger set of items. A filesystem-based db like sqlite might be the best of both worlds. But remember that once you go to a db of any kind, you probably lose the edit-in-the-IDE capability.
David Weinraub