Featuring a variety of content in a CMS

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Featuring a variety of content in a CMS

Post by allspiritseve »

I come across situations once in a while where I want to treat different types of content the same way. For example, in the current site I'm doing a client has requested to be able to feature both pages and images from her gallery in the same box on her homepage. (We currently only have the capability to feature pages). My first thought was to have both Page and Image classes implement a Featurable interface. However, I'd like the possibility of the feature text to be different from the standard content, so that means I'd have to use method names that would never be used on any content item in the future 8O. Also, if I'm pulling information for a feature, I really only need a title, description, image, and link-- the rest of the content would be loaded unnecessarily. So now I'm thinking of making a separate class called Feature that can be generated when editing a page or image-- or edited separately. Does that sound like it would work? What do other people do when needing to treat different content types the same way?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Featuring a variety of content in a CMS

Post by alex.barylski »

I'm not sure I fullly understand the problem...but I assume your using MVC of some sort?

In which case it should be trivial to have two different views pull on the same model...but that doesn't sound like the issue your having...

Can you give breif code examples maybe?
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Featuring a variety of content in a CMS

Post by allspiritseve »

PCSpectra wrote:it should be trivial to have two different views pull on the same model
More like the same view pull on a collection of different domain objects.

Here's an example I pulled from one of our sites:

Code: Select all

<?php foreach ($features as $feature): ?>
<td valign="top" class="feature"><?php if($feature->getImage()): ?>
<div class="featurephoto"><a href="<?php echo $feature->getUrl(); ?>"><img src="userfiles/image<?php echo $feature->getImage(); ?>_small.jpg" alt="" width="120" border="0"/></a> <br clear="all">
</div>
<?php endif; ?>
<h3><a href="<?php echo $feature->getUrl(); ?>"><?php echo $feature->getPageTitle(); ?></a></h3>
<p><?php echo $feature->getSubhead(); ?></p></td>
<?php endforeach; ?>
These methods are specific to Pages. Images might have a separate interface, and ditto for Articles, Posts, News, etc. I want to treat them all the same way, including the ability to sort featured items. Currently we have a field in our pages table that determines sort order, but obviously that wouldn't work if multiple types of content are being displayed.
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: Featuring a variety of content in a CMS

Post by inghamn »

In our CMS, I did the interface-stye thing. I made sure each of the things I was going to feature had the same getter functions available. I didn't bother writing an interface, though. Just made sure they all had getFeaturedTitle(), getFeaturedDescription(), etc. Those would be used when featured the object.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Featuring a variety of content in a CMS

Post by allspiritseve »

inghamn wrote:In our CMS, I did the interface-stye thing. I made sure each of the things I was going to feature had the same getter functions available. I didn't bother writing an interface, though. Just made sure they all had getFeaturedTitle(), getFeaturedDescription(), etc. Those would be used when featured the object.
Yeah, I can see how that'd work. I think I've talked myself into a separate object though.
Post Reply