Pretty urls (how to?)

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
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Pretty urls (how to?)

Post by nervino »

Hi,

I'm trying to set up pretty urls for my module, but I didn't understand how pretty urls work in CMSMS. I have studied New's pretty urls and tried to replicate their behaviour, but without success.

Then, I've found this post ( http://forum.cmsmadesimple.org/index.php?topic=13934.msg68641 ) and my pretty urls began to works.

Now, I would have the ITEM_ID (and other variables) dynamically passed to the url, but I can't figure out how to do it.


The pretty url I would like to have is something like: http://www.mysite/mymodule_name/item_title.htm (with all the other parameters passed but not visible in the url)



in action.default.php I got:
$aliased_title = munge_string_to_url($row['Title']);
  $prettyurl = 'Module/'.$aliased_title;

$par=array();
$par = array('ITEM_ID'=>$row['ITEM_ID'],'returnid'=>$returnid);
$onerow->Title = $this->CreateLink($id, 'detail_page', $returnid, $row['Title'], $par , '', false, false, '', true, $prettyurl);


in MyModule.module.php:

// In this way, pretty urls work, but I have static returnid and ITEM_ID...
$this->RegisterRoute('/[mM]odule\/(?P[A-Za-z0-9-]+)$/',array('action'=>'detail_page','returnid'=>'23','ITEM_ID'=>'234'));
// In this way, pretty urls DON'T work
$this->RegisterRoute('/[mM]odule\/(?P[A-Za-z0-9-]+)$/',array('action'=>'detail_page','returnid'=>$returnid,'ITEM_ID'=>$params['ITEM_ID']));

Thank you


----------------------------------------------

Cms Version: 1.7.1

Installed Modules:

    * CMSMailer: 2.0
    * FileManager: 1.0.2
    * MenuManager: 1.6.3
    * ModuleManager: 1.3.3
    * News: 2.10.5
    * nuSOAP: 1.0.1
    * Printing: 1.0.4
    * Search: 1.6.3
    * ThemeManager: 1.1.1
    * TinyMCE: 2.7.0
    * MyModule: 1.0


Config Information:

    * php_memory_limit:
    * process_whole_template: false
    * max_upload_size: 2000000
    * default_upload_permission: 664
    * assume_mod_rewrite: true
    * page_extension: .htm
    * internal_pretty_urls: false
    * use_hierarchy: true


Php Information:

    * phpversion: 5.3.2-0.dotdeb.1
    * md5_function: On (Vero)
    * gd_version: 2
    * tempnam_function: On (Vero)
    * magic_quotes_runtime: Off (Falso)
    * E_STRICT: 0
    * E_DEPRECATED: 0
    * memory_limit: 128M
    * max_execution_time: 30
    * safe_mode: Off (Falso)
    * session_save_path: /tmp (1777)
    * session_use_cookies: On (Vero)


Server Information:

    * Server Api: apache2handler
    * Server Db Type: MySQL (mysqli)
    * Server Db Version: 5.1.44


----------------------------------------------
vilkis

Re: Pretty urls (how to?)

Post by vilkis »

Hi,
How do you suggest where and how the variables $params['ITEM_ID'] and $returnid are set? The system can only extract variables that you pass to url. If you pass only aliased_title by url how the system can know what is $params['ITEM_ID'] and $returnid?
When you create link using pretty url the variable $params ($par in you case) is ignored.

vilkis
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Pretty urls (how to?)

Post by nervino »

I see.
So, I have to add the variables to $prettyurl, I guess; but in which way? And how can I do this avoiding that those variables are shown in the url too?

thanks a lot
vilkis

Re: Pretty urls (how to?)

Post by vilkis »

The way to not include returnid in url:

In admin panel create preference say 'default_returnid' for default page of your module and save it using function SetPreference. Then in SetParameters()
add code:

Code: Select all

$returnid = $this->GetPreference('default_returnid');
You have to pass the variable ITEM_ID or its alias to url - sorry.

vilkis
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Pretty urls (how to?)

Post by nervino »

Ok, you cleared up my ideas!

Thank you vilkis
domianno
Forum Members
Forum Members
Posts: 12
Joined: Wed Aug 01, 2007 7:17 am
Location: Lithuania, Kaunas

Re: Pretty urls (how to?)

Post by domianno »

I'm modifying Pretty URLs for CGUserDirectory and I want to remove /users/ part.
I've successfully made it, but I am also using news module and pretty URL for news looks like domain.com/news/9/17/Item-title (CGUserDirectory URL now looks like domain.com/username/159).

CGUserDirectory works fine, but when I'm trying to open domain.com/news/9/17/Item-tilte CMSMS calls CGUserDirectory, not News module.

How do I need to modify RegisterRoute in CGUserDirectory or where in CMS MS
I can change which module checks URLs first - CGUserDirectory or News?
As I understand CGUserDirectory has priority to News and thats why CGUserDirectory is called instead of News when link is domain.com/news/9/17/Item-title
vilkis wrote: The way to not include returnid in url:

In admin panel create preference say 'default_returnid' for default page of your module and save it using function SetPreference. Then in SetParameters()
add code:

Code: Select all

$returnid = $this->GetPreference('default_returnid');
You have to pass the variable ITEM_ID or its alias to url - sorry.

vilkis

Identity Studio
vilkis

Re: Pretty urls (how to?)

Post by vilkis »

Hi,
You cannot change the order of check - it is being done in alphabetic order (..C..N..)
vilkis
domianno wrote: How do I need to modify RegisterRoute in CGUserDirectory or where in CMS MS
I can change which module checks URLs first - CGUserDirectory or News?
As I understand CGUserDirectory has priority to News and thats why CGUserDirectory is called instead of News when link is domain.com/news/9/17/Item-title
Post Reply

Return to “Developers Discussion”