Question about Filename field translation

8 posts by 3 authors in: Forums > CMS Builder
Last Post: September 14, 2012   (RSS)

By Shore - September 12, 2012

Hello,

When CMSB transforms the Filename field to the URL slug, does it get saved to the database somewhere so that I could query for the string?

If not, is there a way to build/decrypt the Filename-translation so that I could lookup a record based off the "Title" field for example?

In addition to the ability to lookup by the 'num' at the end of the URL, I'd like to be able to lookup records based on the URL value that CMSB generates from the Filename field.

Thanks!

Re: [cmscott] Question about Filename field translation

By Jason - September 13, 2012

Hi,

The value of the "filename fields" field isn't stored in the database but in the schema file of that given section. There really isn't an easy way of doing this, as a section could have multiple values in filename fields and there isn't a way of knowing which one was used unless you're looking at the values of an individual record.

That being said, if you wanted to base links off of a title instead of a num, you could build up your links manually.

for example:

<a href = "articleDetail.php?title=<?php echo urlencode($record['title']);?>"> <?php echo $record['title'];?> </a>

Then in your detail page, your where clause could be based off of the value of $_REQUEST['title']

If you require this type of searching while still using the value of the _link field, we can certainly look at creating some custom code for you to do that. If you're interested in this, please email consulting@interactivetools.com and we can go over some options.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Question about Filename field translation

By Shore - September 13, 2012

Hi Jason,

The problem I'm running into is that some of my Title field values contain special characters like the % character. These characters get stripped to build the URL slug.

So when I try to do what you suggest, it can't find the record.

Example:

TITLE: 10% off Product A
URL: 10-off-product-a

If I replace the hyphens with blank spaces, then lookup the title, can't find the record because of the % character.

Any ideas?

Thanks!

Re: [cmscott] Question about Filename field translation

By Dave - September 13, 2012

Hi cmscott,

There's a function in /lib/viewer_functions.php called getFilenameFieldValue() that generates the 'slug', but the problem without using the record number is there is nothing to prevent duplicates, so if you have two records:

Hello-World-1
Hello-World-2

Based on the slug without a record number you couldn't get to the original record. Will that be a problem?

Or to approach it another way, if you can let me know what you're trying to accomplish I might be able to think of some other suggestions.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Question about Filename field translation

By Shore - September 13, 2012

Hi Dave,

I'm looking up the record with both the num and title (trying to at least) fields. So there can still be duplicate titles in the table. I should have mentioned that.

Looking up both fields prevents duplicate pages, otherwise you can write anything between the ? and the num and the page resolves to the same content based on the num. I'm also enforcing lowercase. Throwing a 404 error page if the record isn't found.

Hello-World-1 (200)
Goodbye-World-1 (200)
heLlo-wOrlD-1 (200)

Should be:

Hello-World-1 (200)
Goodbye-World-1 (404)
heLlo-wOrlD-1 (404)

IDEALLY, I'd like to add another field to the table that gets auto-populated with the slug - where in my case the slug is the Filename field + num. I'm not too concerned with being able to edit the slug, although that would be nice - kind of like what Wordpress does with their titles.

That way I can easily lookup just the 'slug' field instead of both the 'title' and 'num' fields with no need to worry about de-normalizing the 'title' field for special characters.

Let's say 'title' is my Filename field...

num: 100
title: Get 20% Off Product ABC
slug: get-20-off-product-abc-100

Request comes in, query the db using the slug and return the content or throw a 404 if record isn't found.

Basically, instead of a _link field, I want a _slug field as I described.

I'm also using mod_rewrite to rewrite the viewer urls, but that doesn't impact anything here. Also note I already made slight adjustments to the _link in viewer_functions.php such as strtolower().

/products/product.php?the-slug gets rewritten to /products/the-slug

OTHERWISE, I need a way to de-normalize the 'title' field based on the Filename field.

Hope that makes sense, took a while to write it.

Thanks!

Re: [Dave] Question about Filename field translation

By Shore - September 14, 2012

Hi Dave,

Looks like that could work, I'll test it out later today and let you know how I make out.

Very helpful :)

Thanks!

Re: [cmscott] Question about Filename field translation

By Shore - September 14, 2012

Hi Dave,

Works like a charm! Thank you sir.

Cheers
[:)]