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

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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)
Last edited by harmala on Wed Jan 14, 2009 2:36 am, edited 1 time in total.
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

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

Post 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
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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?
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
point4design
Forum Members
Forum Members
Posts: 68
Joined: Wed Aug 15, 2007 8:11 pm

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

Post 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.
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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.
point4design
Forum Members
Forum Members
Posts: 68
Joined: Wed Aug 15, 2007 8:11 pm

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

Post 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.
harmala
New Member
New Member
Posts: 9
Joined: Fri Jan 09, 2009 6:04 pm

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

Post 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.
Post Reply

Return to “Developers Discussion”