Custom ['_Link']

13 posts by 4 authors in: Forums > CMS Builder
Last Post: April 27, 2010   (RSS)

By Perchpole - April 25, 2010

Hello, All -

Due to the way my latest site works I have to include a category reference in each link. Failure to do so means that certain category-specific functions (such as breadcrumbs and page headers) would cease to work.

As a result, the humble ['_link'] value has become all but redundant. This is a shame as it means (in my case) I have to hard code every link on the site.

Would it be possible to define the structure of "_link" on a site-by-site basis?

I would like to modify the structure so that it inserts "?category=x" into the default code:

xyz/pageDetail.php?category=x&article-1

I assume this would need to be done in the viewer_functions.php or possibly in the page template itself.

Either way, as the operability/flexibility of CMSB increases such modifications are going to become a must. Indeed, I hope an init.php - full of user-defined variables - is already on the drawing board!

Any thoughts?

:0)

Perchpole

Re: [Perchpole] Custom ['_Link']

By aev - April 25, 2010

I second that!

A way of creating dynamic/advanced [_link] values from within the CMSB admin would be a great addition to CMSB. The way it works today has always been totally useless for the sites we build..

-aev-

Re: [Perchpole] Custom ['_Link']

By Jason - April 26, 2010

Hi,

You can control the _link value in CMSB. If you into your section editor and click on "Viewer Urls". You put the file name you want to use (ex. pageDetail.php) in the "Detail Page Url" field. The field "Filename Fields" is where you can specify the fields that will be added to the end of the url. For example, if you entered "category,num" in the "Filename Fields" field, the resulting _link would look like this:

pageDetail.php?category-num (Where "category" and "num" are the values from the database).

I hope this helps. Let me know if you have any more questions.
---------------------------------------------------
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] Custom ['_Link']

By Perchpole - April 26, 2010

Hi, Jason -

Sounds like an interesting solution but, sadly, it doesn't do what I need. Your approach returns the values of the selected fields. It does not permit me to define any additional text.

For it to work I would need to insert category=x into the url - so that it can be passed to the $_REQUEST['category']; code in the resulting page header.

:0/

Perch

Re: [Perchpole] Custom ['_Link']

By Jason - April 26, 2010

Hi,

You can still access those variables. For example, if I had 2 variables in the URL string (say category and num), the string may look like this: pageDetails.php?x-4
Where category=x and num=4.

You could access them by putting this code near the top of your page:
$variables=explode('-',$_SERVER['QUERY_STRING']);
$_REQUEST['category']=$variables[0];
$_REQUEST['num']=$variables[1];


I can now access those 2 variables anywhere below this in the code by using $_REQUEST['category'] or $_REQUEST['num']

Hopefully 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: [Perchpole] Custom ['_Link']

By Dave - April 26, 2010

Hi Perch,

We ourselves use the _link for simple sections, but switch over to custom manually created links anytime we need to do anything more advanced.

We've found this to be the fastest, because _link is always going to be what you expect, it's obvious when looking at the code when links have been customized for something more advanced, and the program doesn't limit what you can do for custom links.

You can access the seo "filename" part of the generated url in this variable though: $record['_filename']

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

Re: [Dave] Custom ['_Link']

By Perchpole - April 26, 2010


We ourselves use the _link for simple sections, but switch over to custom manually created links anytime we need to do anything more advanced.



Hi, Dave -

Yes, I apreciate that. I just wondered if the idea was within the realms of do-ability or not!

Still hoping for an init.php set-up though.

:0)

Perch

Re: [Perchpole] Custom ['_Link']

By Dave - April 26, 2010

>Still hoping for an init.php set-up though.

I'm not sure if we're both talking about the same thing, but if we want to have custom modifications that are specific to a site they way we do that is to create a custom plugin for a site named /cmsAdmin/plugins/sitename-custom.php

And if I wanted to change how _link worked I'd put it at the top of the page, something like this:

// load records
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
));

// create custom _link values
foreach (array_keys($newsRecords) as $index) {
$record = &$newsRecords[$index];

$record['_link'] = '';
$record['_link'] .= "?category=" . urlencode($record['category']);
$record['_link'] .= "&" .$record['_filename']. '-' . $record['num'];

unset($record);
}


Basically what that does is overwrite _link for all the records.

If you wanted to modify how _link worked site wide I could add a plugin filter hook for that value to CMSB. Then you could have a plugin that output custom _link values based on the table, record, etc.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Custom ['_Link']

By aev - April 27, 2010

Dave,

this is a great tip! I'll bookmark this one.

Just one thing.. what is the & in the line after the foreach statement:
$record = &$newsRecords[$index];

-aev-