[SOLVED] Is there a built in function for creating a slug?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

[SOLVED] Is there a built in function for creating a slug?

Post by scooper »

I'm putting together a module that inlcudes pretty URLs generated from an entry title. So if I have a entry called "About about earwigs" then I'd end up with something like:

/newmodule/13/12/all-about-earwigs

It occurs to me that we must do this kind of slug creation somewhere when we create aliases, but having skimmed through the api docs I couldn't see anything obvious.

It's not a big deal if not because it's only a few lines to create my own function, but hey, I like to reuse code if it's there.
Last edited by scooper on Fri Jun 27, 2014 10:58 am, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Is there a built in function for creating a slug?

Post by Jos »

You can check News module as an example » action.default.php

Code: Select all

    $prettyurl = $row['news_url'];
    if( $prettyurl == '' ) {
      $aliased_title = munge_string_to_url($row['news_title']);
      $prettyurl = 'news/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title";
and

Code: Select all

    $onerow->morelink = $this->CreateLink($id, 'detail', $detailpage!=''?$detailpage:$returnid, $moretext, $sendtodetail, '', false, false, '', true, $prettyurl);
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

[SOLVED] Is there a built in function for creating a slug?

Post by scooper »

Excellent - thanks for that Jos - munge_string_to_url is exactly what I was after.
Post Reply

Return to “Developers Discussion”