More Issues With selectedCategoryNum

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 29, 2010   (RSS)

By Perchpole - March 26, 2010

NB: I've already outlined similar problems in this thread...

$selectedCategory and Pagination conflict?

I've now encountered another issue which also has the potential to mess things up.

When using a search query which includes a space, such as...

www.mysite.com/index.php?category=3&type=diesel engine

...the returned selectedCategoryNum is always 20.

Presumably this is because of the way URL encoding replaces spaces with %20.

As selectedCategoryNum is defined by getNumberFromEndOfUrl, the system concludes that category 20 has been loaded.

Interestingly, it does this even though a category number has already been defined in the URL! The system seems to over-ride this information because %20 is the last number in the string.

I hate to keep banging on about this issue but it's proving to be a real thorn in my side. I'm trying to design dynamic pages which load/filter content based on specific criteria. Often the most important factor is the selected category as this dictates which sub-menus and supplementary page info is displayed.

If this framework isn't consistent, the whole thing falls apart - rendering it next to useless.

I really hope this issue is on the to-do list!

:0/

Perch

Re: [Perchpole] More Issues With selectedCategoryNum

By Chris - March 29, 2010

Hi Perch,

Wow, great find! This certainly does make a case for this feature being fixed immediately. So, here it is!

The next version of CMS Builder will have this fix built in, but if you'd like, you can make the change right now to your copy:

Open up cmsAdmin/lib/viewer_functions.php and change this line:

if (!@$options['selectedCategoryNum']) {

...to this:

if (!array_key_exists('selectedCategoryNum', $options)) {

Now you can explicitly state in your viewers:

'selectedCategoryNum' => 0,

...which will avoid the automatic behaviour of using getLastNumberInUrl.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [Perchpole] More Issues With selectedCategoryNum

By Chris - March 29, 2010

Hi Perchpole,

Sorry, I thought this issue was more related to the other thread than it is.

Does this work?

'selectedCategoryNum' => @$_REQUEST['category'],

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] More Issues With selectedCategoryNum

By Perchpole - March 29, 2010

Hi, Chris -

It actually works (best) like this...

$homeCategoryNum = 1;
$selectedCategoryNum = @$_REQUEST['category'];
if (!$selectedCategoryNum) { $selectedCategoryNum = $homeCategoryNum; }

Then...

'selectedCategoryNum' => $selectedCategoryNum,

Deffinitely getting somewhere!

:0)

Perch