Hi,
I've created a news section for my site that uses the awesome DataObjectManager, and with some help from UncleCheese I've got it working with categories, with the end goal of having a much easier to use news archive in the CMS (there's likely to be more than a few hundred news articles in the next year or so, and the sitetree system can't handle it).
I've got each NewsArticle displaying on its own 'page', by using a function on the NewsHolder (which sits at /news in the site):
function display() {
$params = Director::urlParams();
$id = (int)$params['ID'];
$object = DataObject::get_by_id("NewsArticle", $id);
if($object) {
return $this
->customise(array('NewsArticle' => $object))
->renderWith(array('NewsArticle', 'Page'));
} else {
Director::redirect('not-found');
}
}
So when I go to /news/display/1 it shows me the first NewsArticle in a nice template.
My question is this - and I know it's kind of an overlap with how Objects and Pages work, but anyway - is there a way to generate a friendly URL instead of displaying by ID? I'd like to get something like /news/display/news-title-here working, but can't work out the best way to do it.
* Should I create a url-slug field in the NewsArticleObject, and set that on creation somehow, then call that from the Display function, or,
* Is there a function for returning a friendly url based on a field on the Object (e.g. Title)?
Any help on this is much appreciated!
Les