开发者

Simple Content Storage in Zend Framework (no DB)

I am working on an existing website that uses Zend Framework, and I am trying to avoid hard-coding content that needs to be dynamic in nature.

I have a list of articles that need to be output as links with or without a description. Each link generates a dynamic page that will output the full article with a breadcrumb and a link list of the other article titles, saving state to 开发者_开发技巧highlight the current article. I have a template ready to take each variable, but first I need a content source.

Because the list is somewhat short, we do not feel it should be stored in the database (how would I even enter/edit said content in the database without a CMS?).

Can this be done by parsing an XML document, or is there another method I am not thinking of? I've used SimpleXML on non-Zend PHP sites but calling the class directly doesn't seem to work (I think it might be a path issue).

EDIT: I ended up using the solution recommended by prodigitalson:

I created an XML file for my content's meta data (title, hash, description, include file) and put it in my app/modules/default/model folder. I then laid out each full article as an include snippet, and put the files in views/partials. I created a custom class with the methods I needed and put it in my library folder -- then, I instantiated my class in the controller's init() method. Then, the object was available to all pages/actions within that controller.

Then, I can call any method from the controller-instantiated object in a corresponding view. I'm able to output links, full articles and everything else I need by using this approach. I'm passing the current URL param (hash) to the class before outputting the link list in order to highlight the current link.


Id probably stick with XML (or ini if you prefer) to store the meta info for the articles (path to html file, nav title, url/url params).Then instead of SimpleXML id use Zend_Config_Xml (or ini). to pull int he info. From there it shoudl jsut be a matter of pulling the varibales you need out of it and including the actual content file (which i would keep completely separate from the config - just store the path to the "content" file).


Use an array. You can put your data in a separate file :

// in data.php
return array(
  array("data1", "data2"),
  array("data3", "data4")
);

// to access data
$data = require('data.php');

It's simpler and faster (and ugly but it's PHP ;-) )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜