Adding extra text relating to the URL

11 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2009   (RSS)

By isdoo - June 15, 2009

Hi,

Could someone point me in the right direction, as I can't figure this one out.

Essentially I am using a URL of say /news/index.php?division=hotel or more likely /news/index.php/division-hotel

I can use the

<?php echo $_GET['division']; ?> to grab the division for the first option, but that fails for the second option & also fails if the URL is entered just as /news/index.php

However I would like to add extra info on the page depending upon division.

So for example if division=hotel then include external file /news/x.php if division=shop then include /news/y.php if there is no value to division then include /news/z.php

Solving the above would mean only having to create one page.

I have included

<?php echo $_GET['division']; ?>
<?php if ('division' == 'hotel'):?><h2>Hotel</h2>
<?php elseif ('division' == 'shop'): ?><h2>Shop</h2>
<?php else: ?><h2>Other Division</h2>
<?php endif ?>


This works fine as long we do not have /news/index.php without a division mentioned, as we then get an error of Notice: Undefined index: division in /path/to/news/index.php on line 24

It also fails in /news/index.php/division-hotel

Although I have yet to try it, I cannot see why replacing the <h2>Hotel</h2> with the include instruction shouldn't work.

Hopefully you are still with me ;)

I therefore have two questions.....

1) How would I get the code to work with.....
a) /news/index.php and
b) /news/index.php/division-hotel

2) As I would have to replicate this code several times, I might go for individual pages (although I would like to avoid this) - but if I did (useful for reference anyway) how would we display only news items for a particular division and nothing else. So /news/hotel/index.php would display records relating to the division equals hotel etc.

Many thanks.

Re: [isdoo] Adding extra text relating to the URL

By isdoo - June 15, 2009

I think the answer to the seconds question might be....

<?php if division == hotel: ?>
POSTED AROUND THE CODE TO DISPLAY THE NEWS ITEMS FOR HOTEL DIVISION
<?php endif ?>


Unless there is a simpler method.

Not sure on the first question mind.

Re: [isdoo] Adding extra text relating to the URL

By isdoo - June 15, 2009

Actually this would not work, as I need to pull the 'division' into my page title - so need something for the header section.

Re: [isdoo] Adding extra text relating to the URL

By ross - June 15, 2009

Hi there

There are a couple things happening here so I made some changes to your code. Have a look:

<?php echo @$_GET['division']; ?>
<?php if (@$_GET['division'] == 'hotel'):?><h2>Hotel</h2>
<?php elseif (@$_GET['division'] == 'shop'): ?><h2>Shop</h2>
<?php else: ?><h2>Other Division</h2>
<?php endif ?>


The first thing to notice is that each time you refer to 'division', you always need to have the $_GET in there. The second thing is that I added in "@" each time you have the $_GET. That will get rid of your undefined variable error when you are on just index.php and there is no division specified. The @ basically suppresses the error message.

Try that out and let me know where it gets you to :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Adding extra text relating to the URL

By isdoo - June 15, 2009

Thanks ross.

Any suggestions on only displaying records from one division if we just have index.php and no division in the URL?

Just concerned that someone might enter /news/hotel rather than say /news/hotel/index.php?division=hotel

If we go down the line of putting the pages into seperate folders due to the many customisations in each section.

Just not sure on the route, I will go down yet - but if the later is not an option then I have to think about how to pull in the various bits effectively.

Many thanks.

Re: [isdoo] Adding extra text relating to the URL

By ross - June 16, 2009

Hi there.

Glad that's all working :). If you end up having a separate index page for each division, you just need to put

'where' => "division = 'hotel'"

up in the viewer code. To start with though, don't worry about it. Just make your index pages with the default code and let me have a look. I can show you in more detail how to set them up to be divisions specific.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Adding extra text relating to the URL

By isdoo - June 16, 2009

Thanks - must admit CMS Builder is far better than I thought it would be!

It isn't perfect, not because of faults but for features that would make it better (for example would be great to have previous page | next page & Page number at the foot of a list of records rather than having to scroll to the top if you wanted the next page).

I have several 'issues' okay more questions, but they are probably more than a forum is for ( do not feel it is fair to open extra posts), so guess will need to buy some contracting time to get me on the right road.

Thanks again.

Re: [ross] Adding extra text relating to the URL

By isdoo - June 17, 2009

Thanks - I meant within the CMS itself, rather than on the produced pages.

When viewing the list of records etc.

Re: [isdoo] Adding extra text relating to the URL

By ross - June 18, 2009

Hi there.

Thanks for posting!

The interface templates aren't really something we support modification on. The main thing is that eachtime you do an upgrade, those changes will be overridden. If you want, we could have a look at this through consulting (consulting@interactivetools.com). Drop me a line if you are interested :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/