Getting pretty urls with CTLModuleMaker

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
vandamhans
New Member
New Member
Posts: 5
Joined: Mon Jan 10, 2011 3:50 pm

Getting pretty urls with CTLModuleMaker

Post by vandamhans »

Hi guys,

I'm trying to get "pretty urls" for the module I made with CTLModuleMaker, but I can't make it happen.

I read the FAQ but I do not become really wiser afterwards.

I understand I have to change something in the Routes.php file, but not exactly what.

My module is called "Products" and in my module I have one entity called Products.

I would like to have an url like /products/itemname/returnid
What do I have to add to the routes.php file? And do I have to change something to my .htaccess file?

The FAQ-part I don't understand is the following:
In later versions, the module creation wizard will handle routes and hierarchies setup. Until then, you have to setup routes manually - but it's far from complicated. It's all done in the module_specific/Routes.php file.

Let's say I have a module with two entities, called "category" and "item" (with each item having a dropdown field in which a category is selected). I wish to have an url of the form mymodule/category/returnid when I look at a category, and mymodule/category/item/returnid when I look at an item.
Right now, the Routes.php file is almost empty, with only two empty variables. We won't use the hierarchies variable, but we will populate the routes variable. The routes variable should be an array of routes, each route being in turn an array with three keys: "rule", "builder" and (optionally) "defparams". So our variable will have this kind of structure:

Code: Select all

$routes = array(
			array(
					'rule' => string,
					'builder' => array,
					'defparams' => array
				)	
		);
The "rule" element is exactly what one would put in the RegisterRoute function used in other modules. Therefore, I won't explain it in details here. The reason we put it here is that the module will use it to register routes, but also to read them and to create pretty urls.
Likewise, the "defparams" is exactly like in the RegisterRoute function: it is an array of default parameters that are not in the url. Usually, it will be array("action"=>"default"). "builder" is an array of the different parts of the url, in the order in which they appear. The key is what should be shown, and the value is the type of what is show (either a parameter or a string).

In our example, we would probably setup the following route:

Code: Select all

$routes = array(

	array(	'rule' => '"mymodule\/(?P<category>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
			'builder' => array(	'mymodule' 	=> 'string',
								'category' 	=> 'param',
								'item'		=> 'param',
								'returnid'	=> 'param'
							),
			'defparams' => array('action'=>'default', 'what'=>'item')
	),
	
	array(	'rule' => '"mymodule\/(?P<category>[^/]+)\/(?P<returnid>[0-9]+)$"',
			'builder' => array(	'mymodule' 	=> 'string',
								'category' 	=> 'param',
								'returnid'	=> 'param'
							),
			'defparams' => array('action'=>'default', 'what'=>'category')
	)
		
);	

Once you've understood this, the module should do the rest.

Of course, more rules might be needed. In our example, pretty urls to items require that the category parameter be specified. If it isn't (like in search results), there's no pretty url. So we might want to also add and url without category, like:

Code: Select all

array(	'rule' => '"mymodule\/details\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
			'builder' => array(	'mymodule' 	=> 'string',
								'details' 	=> 'string',
								'item'		=> 'param',
								'returnid'	=> 'param'
							),
			'defparams' => array('action'=>'default', 'what'=>'item')
	)

And keep in mind that routes with less parameters should always be after those with more parameters.
vandamhans
New Member
New Member
Posts: 5
Joined: Mon Jan 10, 2011 3:50 pm

Re: Getting pretty urls with CTLModuleMaker

Post by vandamhans »

I have put on prettyurls in the config.php file of CMSMS now.

The url to the detail page is now "index.php?mact=Ereaders,cntnt01,default,0&cntnt01what=Ereaders&cntnt01alias=BeBook_One&cntnt01returnid=59"

I would like to have it changed to "index/Ereaders/BeBook_One/59/"

What do I have to add to the Routes.php file? And do I have to change anything to the .htaccess file?
I have tried so much different things but nothing really works..

Thanks in advance!
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Getting pretty urls with CTLModuleMaker

Post by plger »

On top of my head, you could try this (make sure no page has the alias "Ereaders"):

Code: Select all

$routes = array(
   array(   'rule' => '"Ereaders\/(?P<alias>[^/]+)\/(?P<returnid>[0-9]+)$"',
         'builder' => array(   'Ereaders'    => 'string',
                        'alias    => 'param',
                        'returnid'   => 'param'
                     ),
         'defparams' => array('action'=>'default', 'what'=>'Ereaders')
   ) 
);
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Getting pretty urls with CTLModuleMaker

Post by plger »

Or this:

Code: Select all

$routes = array(
       array(   'rule' => '"readers\/(?P<Ereaders>[^/]+)\/(?P<returnid>[0-9]+)$"',
             'builder' => array(   'readers'    => 'string',
                            'Ereaders'    => 'param',
                            'returnid'   => 'param'
                         ),
             'defparams' => array('action'=>'default', 'what'=>'Ereaders')
       )
    );
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker 2.0.3

Post by andrewvideo »

Hi people.

Sorry I cant get my head around this and cant get to work can anyone help me please. What am I doing wrong.

Thank you

Here is my url

Code: Select all

index.php?mact=MediaCentre,cntnt01,default,0&cntnt01what=Videos&cntnt01alias=showrealvideo&cntnt01returnid=23
This code I am trying to get to work

Code: Select all

<?php
		

		$hierarchies = array();
		$routes = array(
		       array(   'rule' => '"MediaCentre\/(?P<Videos>[^/]+)\/(?P<returnid>[0-9]+)$"',
		             'builder' => array(   'Videos'    => 'string',
		                            'Videos'    => 'param',
		                            'returnid'   => 'param'
		                         ),
		             'defparams' => array('action'=>'default', 'what'=>'Videos')
		       )
		    );
		
		
	
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Getting pretty urls with CTLModuleMaker

Post by plger »

You miss the MediaCentre string. In addition, there's no "Videos" parameter in your url, so this rule cannot apply.
You could try a rule like:

Code: Select all

array(         'rule' => '"MediaCentre\/(?P<what>[^/]+)\/(?P<alias>[^/]+)\/(?P<returnid>[0-9]+)$"',
                   'builder' => array(   
                                  'MediaCentre'    => 'string',
                                  'what'    => 'param',
                                  'alias'    => 'param',
                                  'returnid'   => 'param'
                               ),
                   'defparams' => array('action'=>'default', 'what'=>'Videos')
             )
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

Hi

I cant still cant get to work. :'( There must some else I need to check. I am really confessed now. The news module is work with perry urls.

My here my Url and its has got Videos in the url.

I am been trying everything I can think of.
Thank you and sorry I am not a really that good with php stuff.

Code: Select all


/index.php?mact=MediaCentre,cntnt01,default,0&cntnt01what=Videos&cntnt01alias=Youtubetest1&cntnt01returnid=23

Code: Select all

<?php	

		$hierarchies = array();
		$routes = array(   
		array(   'rule' => '"MediaCentre\/(?P<what>[^/]+)\/(?P<Videos>[^/]+)\/(?P<returnid>[0-9]+)$"',
		             'builder' => array(   
					    'MediaCentre'    => 'string',
					    'what'    => 'param',
					    'alias'    => 'param',
					    'returnid'   => 'param'
					                               ),
 'defparams' => array('action'=>'default', 'what'=>'Videos')
		       )
		    );
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

Right I try this with with an older CMMS 1.8.1 "Mankara" and same module I made with CTLModuleMaker. Just copy over one ftp to other ftp and try it and it works great. When I use CMSMS 1.9.4 "Faanui" the petty urls dont work. But If I enter the petty url in manley the page

so what I did is

this is the original url

Code: Select all

http://www.shiftmedia.org.uk/index.php?mact=MediaCentre,cntnt01,default,0&cntnt01what=Videos&cntnt01alias=Youtubetest1&cntnt01returnid=23
and mainly change it to in the address bar too

Code: Select all

/MediaCentre/Youtubetest1/23
and comes up and works.

inside the Routes.php This works with CMMS 1.8.1 not with CMSMS 1.9.4 or is there I am missing out in the new install of CMSMS. Also .htaccess is the same.

Can anyone help please.

Thank you



This is the working Routes.php with CMMS 1.8.1

Code: Select all


<?php
		

		$hierarchies = array();
		$routes = array(

		   array(   'rule' => '"MediaCentre\/(?P<Videos>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCentre'    => 'string',
		                        'Videos'    => 'param',
		                        'item'      => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'item')
		   ),

		   array(   'rule' => '"MediaCentre\/(?P<Videos>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCentre'    => 'string',
		                        'Videos'    => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'Videos')
		   )

		);

andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

this is my CMSMS report might help

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

Cms Version: 1.9.4

Installed Modules:

* CMSMailer: 2.0.1
* FileManager: 1.1.0
* MenuManager: 1.7.6
* ModuleManager: 1.4.1
* News: 2.11.2
* nuSOAP: 1.0.2
* Printing: 1.1.2
* Search: 1.6.10
* ThemeManager: 1.1.4
* TinyMCE: 2.8.4
* CGSimpleSmarty: 1.4.3
* Captcha: 0.4
* Album: 0.9.3
* AkismetCheck: 0.2.1
* GoogleMaps: 0.1.8
* MediaCentre: 1.0
* MultiUpload: 0.1.0
* NeoDataStorage: 0.2.3
* NeoModule: 0.2.4
* plFileHandler: 0.4.1
* Statistics: 0.9.9
* TemplateExternalizer: 1.2
* NeoUpload: 0.3.1
* CGExtensions: 1.17.8
* CGCalendar: 1.3
* CGFeedback: 1.0.5
* CGFeedMaker: 1.0.9
* Archiver: 0.2.4
* FormBuilder: 0.6.2


Config Information:

* php_memory_limit:
* process_whole_template: false
* output_compression: false
* max_upload_size: 100000000
* default_upload_permission: 664
* url_rewriting: mod_rewrite
* page_extension: /
* query_var: page
* image_manipulation_prog: GD
* auto_alias_content: true
* locale:
* default_encoding: utf-8
* admin_encoding: utf-8
* set_names: true


Php Information:

* phpversion: 5.2.9
* md5_function: On (True)
* gd_version: 2
* tempnam_function: On (True)
* magic_quotes_runtime: Off (False)
* E_STRICT: 0
* memory_limit: 128M
* max_execution_time: 180
* output_buffering: On
* safe_mode: Off (False)
* file_uploads: On (True)
* post_max_size: 105M
* upload_max_filesize: 100M
* session_save_path: /tmp (0777)
* session_use_cookies: On (True)
* xml_function: On (True)


Server Information:

* Server Api: cgi-fcgi
* Server Db Type: MySQL (mysql)
* Server Db Version: 5.0.92


----------------------------------------------
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

I found that Getting pretty urls with CTLModuleMaker in Version CMSMS 1.9.4. I had them working nice with CMSMS 1.8.1.

If anyone know about the problem or how to fix this problem.

Cheer

Andrew
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

I got Getting pretty working by adding '$config['use_hierarchy'] = true ;' in the config file. In new CMSMS is not there anymore.
ataxel
Forum Members
Forum Members
Posts: 41
Joined: Thu Jul 19, 2007 1:32 pm

Re: Getting pretty urls with CTLModuleMaker

Post by ataxel »

I have the same problem make this happen in CMSMS 1.10.3
I don't know what and where i miss if someone can help.

[...]/_centreagni.com/index.php?mact=formations,cntnt01,default,0&cntnt01what=formations&cntnt01alias=reiki-initiation-en&cntnt01returnid=59

Code: Select all

<?php
$hierarchies = array();
$routes = array(
   array(   'rule' => '"formations\/(?P<what>[^/]+)\/(?P<alias>[^/]+)\/(?P<returnid>[0-9]+)$"',
         	'builder' => array(   
			'formations' => 'string',
			'what'    => 'param',
                         'alias'    => 'param',
                         'returnid'   => 'param'
                     ),
         'defparams' => array('action'=>'default', 'what'=>'formations')
   ) 
);
bojtia
New Member
New Member
Posts: 4
Joined: Thu Feb 16, 2012 12:23 pm

Re: Getting pretty urls with CTLModuleMaker

Post by bojtia »

Hello!
Pretty URL-s are working for me, but I would like to get rid of the returnid. I have read the FAQ, and I managed to change the "detail" part, but if I try to remove the returnid, the content of my page disappears.
In mymodul.module.php I commented out this:

Code: Select all

// $prettyurl .= "/".$returnid;
		return $prettyurl;
In the function setparameters part I had this before:

Code: Select all

		$this->RegisterRoute("/[kK]irandulababa\/([Qq]uery)\/(?P<query>[0-9]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/([Qq]uery)\/(?P<query>[0-9]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/([Kk]irandulas)\/(?P<alias>[^\/]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<parent>[^\/]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)\/(?P<returnid>[0-9]+)$/", $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<parent>[^\/]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)\/(?P<returnid>[0-9]+)$/", $defact);
I removed the returnid parts, and put the array tag

Code: Select all

		$this->RegisterRoute("/[kK]irandulababa\/([Qq]uery)\/(?P<query>[0-9]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/([Qq]uery)\/(?P<query>[0-9]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/([Kk]irandulas)\/(?P<alias>[^\/]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<parent>[^\/]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)$/", array("returnid"=>56), $defact);
		$this->RegisterRoute("/[kK]irandulababa\/(?P<what>[^\/]+)\/(?P<parent>[^\/]+)\/(?P<pageindex>[0-9]+)\/(?P<nbperpage>[0-9]+)$/", array("returnid"=>56), $defact);
It does not work.
Can anybody help?
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Getting pretty urls with CTLModuleMaker

Post by andrewvideo »

Hi I am trying to get those to work together but no luck. Can anyone help. I would be so happy if someone help fix this problem.

I can get one to work or the other to work but not both, I would like them both working together.

Thank you

Andrew

Code: Select all

<?php
$hierarchies = array();
	
		$routes = array(	

		   array(   'rule' => '"MediaCenter\/(?P<videos>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'videos'    => 'param',
		                        'item'      => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'item')
		   ),

		   array(   'rule' => '"MediaCenter\/(?P<videos>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'videos'    => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'videos')
		   ),
		  array(   'rule' => '"MediaCenter\/(?P<categories>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'categories'    => 'param',
		                        'item'      => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'item')
		   ),

		   array(   'rule' => '"MediaCenter\/(?P<categories>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'categories'    => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'categories')
		   )		
		
		); 


I can get this work on its own.

Code: Select all

  array(   'rule' => '"MediaCenter\/(?P<videos>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'videos'    => 'param',
		                        'item'      => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'item')
		   ),

		   array(   'rule' => '"MediaCenter\/(?P<videos>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'videos'    => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'videos')
		   ),
I can get this work on its own.

Code: Select all

array(   'rule' => '"MediaCenter\/(?P<categories>[^/]+)\/(?P<item>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'categories'    => 'param',
		                        'item'      => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'item')
		   ),

		   array(   'rule' => '"MediaCenter\/(?P<categories>[^/]+)\/(?P<returnid>[0-9]+)$"',
		         'builder' => array(   'MediaCenter'    => 'string',
		                        'categories'    => 'param',
		                        'returnid'   => 'param'
		                     ),
		         'defparams' => array('action'=>'default', 'what'=>'categories')
		   
Post Reply

Return to “Modules/Add-Ons”