Page 1 of 1

Clean URL issue with new module I'm developing [SOLVED]

Posted: Fri Jan 09, 2009 6:23 pm
by harmala
Hello everyone,

I'm a newcomer to CMSMS and I am already a huge fan. I plan on using CMSMS for many projects in the future, and I hope I can help add to the community effort.

I'm developing a new module that handles basic "Store Locator" functions. Everything is working great, except I'm having an issue mapping clean URLs for my new module. Specifically, I seem to have everything working correctly, except that the wrong page template loads. For some reason, my Home Page template loads when displaying the "Store Detail" page, even though all the other pages use the Locations page as they should.

Here are some examples from the development site:

http://67.205.50.108/
This is the home page. Not terribly relevant, except that it is a unique template used only for the Home Page. Notice the row of boxes along the bottom.

http://67.205.50.108/locations
This is the Locations module "Main Page". It works perfectly and uses the Location template correctly.

http://67.205.50.108/index.php?mact=Locations,m4,detail,1&m4alias=denver&m4returnid=57
This is the Locations module "Detail Page", using the long URL. Again, works perfectly and uses the correct template. (Note: I edited the post to use a long URL that mirrors the clean URL functionality exactly...this example was different originally.)

http://67.205.50.108/locations/denver/
And...here's the issue. I can map the parameter I need (the "page alias") and it calls the correct action for the Locations module, grabs the correct data...but uses the Home Page template!?

I've tried some debugging, but to no avail. I've tried passing various parameters as defaults, I've checked variables during runtime to make sure the module name was passed correctly, etc. I can't figure out why it uses the Home Page template.

Here is the SetParameters function in place at the moment:

Code: Select all

  function SetParameters()
  {	
    
    $this->CreateParameter('locations', '', $this->lang('help_locations'));

    $this->SetParameterType('alias', CLEAN_STRING);
    
    $this->RegisterRoute('/[Ll]ocations\/(?P<alias>[a-zA-Z]+)$/',array('action'=>'detail'));
  }
Any help would be greatly appreciated. I'd love to release this module once I get all the bugs worked out, I imagine some other folks could use it, too.

EDIT: I should also note that I've tried passing the "returnid" parameter of 57 as a default, and even as another parameter in the URL (just to see if it would work), but the script then performs the default action instead of the detail action, even though the action parameter is being set in the defaults array. I'm sure this is important, since the Locations page is id#57, but I'm not sure how to pass it correctly or what effect it has on this implementation.

Thanks!

(Edited as noted above)

Re: Clean URL issue with new module I'm developing

Posted: Sat Jan 10, 2009 10:09 pm
by tyman00
I have no experience developing modules or setting up pretty urls. Try using m4returnid=57 not just returnid.

you can also try using other modules for examples. i.e. News and Products they both have parameters in their Pretty URLS to specify a detail page

Re: Clean URL issue with new module I'm developing

Posted: Mon Jan 12, 2009 6:16 pm
by harmala
Thanks for your help. I've tried passing both "returnid" and "m4returnid" as default parameters, with different results. The "m4returnid" does nothing. Passing "returnid" causes the default action to occur, even though I set "action" equal to "detail" in the parameters. If I don't pass the "returnid" but otherwise leave the route the same, the "detail" action is called correctly, but the output is displayed inside the Home template instead of the Locations template.

I'm totally stumped. Anyone else out there have any clue as to what I'm missing or why this could be happening?

Re: Clean URL issue with new module I'm developing

Posted: Wed Jan 14, 2009 2:35 am
by harmala
OK, I finally solved this, but in the process, I may have uncovered a potential bug in CMSMS itself, or at least a serious problem when trying to build modules. Someone with more experience may be able to tell me why this is happening, but for the time-being, here's what solved it for me.

I had to set all the parameters that the index.php page expects when it tries to construct the "mact" array in the defaults of the route I registered, including the inline setting, id and returnid (plus the action, which I already knew). However, this presents a problem. If you pass the id this way, index.php doesn't grab it from the defaults array until after it constructs an array of parameters passed in the URL...and the array uses the id as part of the key. So, the parameters passed in the URL are named using the default id in index.php instead of the one you pass, while the rest of parameters passed in the "defaults" array do. Not good.

The solution was to add a special case earlier in index.php that checks the $page variable...if "locations" (the name of my module) is in the URL, it sets the default id to the one I need instead of the usual default. It's a hack, so I'd love to know a better way to solve this.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Wed Jan 14, 2009 4:55 am
by calguy1000
That's why we pass the returnid in the URL.
If you look at News.module.php in the SetParameters method you'll see it.

And it's not a bug.... it's a design decision.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Wed Jan 14, 2009 4:13 pm
by harmala
calguy1000 wrote: That's why we pass the returnid in the URL.
If you look at News.module.php in the SetParameters method you'll see it.

And it's not a bug.... it's a design decision.
Thanks, calguy. That clears that up. I didn't mean any disrespect, it was just a long hard road to get to where I needed to be.

And, to clarify that, I really don't give a rat's ass about clean URLs...I've always felt that if your site is good, the engines will spider it, regardless. But, my clients are a totally different story. And, in this case, passing the returnid or any other parameter in the URL was not an option. To be fair, they had a lot of existing links out there that would have broken, so they weren't just being picky. It seemed like a legitimate request.

As I mentioned in another thread, I'd like to be part of the solution and not just a whiner. Now that I've developed a module that can get around the need to pass other parameters in the URL (as a hack), maybe I can help find a good way to implement that in CMSMS itself so that modules who choose to implement an alias system or some such to achieve really clean URLs can do so.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Wed Jan 14, 2009 4:15 pm
by calguy1000
some modules are now using a preference to determine a default returnid
However, this has other more difficult problems, particularly during the upgrade process.... that I haven't resolved yet.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Fri Mar 20, 2009 4:22 pm
by point4design
harmala, any interest in releasing the module. I'd love to 'test' it for you. I have a need for something exactly like what you've built.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Fri Mar 20, 2009 4:33 pm
by harmala
I'd like to release it, but I haven't had much time to clean up the code. I'm about to beta launch a huge web project (like, today), so the Locations module has been left in good-enough-for-the-original-client state. So, lots of hacks and ugliness.

That said, if someone wants to deal with all that to at least have a head start, I would love to help out the community. I have another CMSMS project coming up in April, so I'll be back in the mind-set to help out more.

If you are still interested, reply here and I'll see what I can do to get it into good enough shape. If nothing else, I can send you the code privately and let you see what you can get out of it.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Fri Mar 20, 2009 4:36 pm
by point4design
harmala wrote: I'd like to release it, but I haven't had much time to clean up the code. I'm about to beta launch a huge web project (like, today), so the Locations module has been left in good-enough-for-the-original-client state. So, lots of hacks and ugliness.

That said, if someone wants to deal with all that to at least have a head start, I would love to help out the community. I have another CMSMS project coming up in April, so I'll be back in the mind-set to help out more.

If you are still interested, reply here and I'll see what I can do to get it into good enough shape. If nothing else, I can send you the code privately and let you see what you can get out of it.
Yes, please send me a copy if you don't mind. It'd be better than starting from scratch. Anything I improve I will send back to you and can be released to the community.

Re: Clean URL issue with new module I'm developing [SOLVED]

Posted: Fri Mar 20, 2009 4:41 pm
by harmala
Sounds good. I'm slammed this morning but I'll try to get to it later today or this weekend. I'll update this thread when I've got something and we'll figure out how to get it to you.