Forums / Developer / Removing custom module index page ?

Removing custom module index page ?

Author Message

H-Works Agency

Wednesday 15 July 2009 1:33:08 am

Say you make a custom module named "custom" with starting page "index.php" and with params "contentNodeID"

In module.php you would have :

$ViewList['index'] = array( 'script' => 'index.php',
'params' => array( 'contentNodeID' ));

In this case the page url would be : "domaine/custom/index/39483"

Then i want to remove "index" from the url like this :

$ViewList[''] = array( 'script' => 'index.php',
'params' => array( 'contentNodeID' ));

In this case the page url should be : "domaine/custom/39483"

The problem is that due to the contentNodeID param this syntax causes an error.

In fact it works if you just hit : "domaine/custom/" but not with the param.

Is there something i am missing to have this syntax working with module params ?

I hope my description is clear enough. Cheers. M

EZP is Great

André R.

Wednesday 15 July 2009 2:33:35 am

I'm amazed that $ViewList[''] is valid php, but anyway, doesn't seemd to work. If the module only have one view, then you should look into using the singel function support.

HowTo: Avoid defining $ViewList, and just define the singel function in $Module['function'] like:

$Module = array( 'name' => 'Custom',
                 'variable_params' => true,
                 'function' => array( 'script' => 'index.php',
                                             'params' => array( 'contentNodeID' ) )
);

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

H-Works Agency

Wednesday 15 July 2009 2:50:34 am

This technique allow to make compact module adresses by removing the second element in module's view uri.

But my exemple is not only for a "one view module" but to define a module "index" page...after $ViewList[''] you can add $ViewList['myview'].

The second benefit of defining this "empty" view is that people playing with their browser address won't arrive on a "undefined view" error when removing module's view name from the address.

I wasn't aware of your technique, i am gonna try it right away.

Thanx

EZP is Great

Bartek Modzelewski

Wednesday 15 July 2009 3:08:03 am

Hi Martin,

have you tried to use URL Translator in admin interface, and setup the following rule:

New URL alias: custom
Destination: custom/index
and remeber to uncheck "Alias should redirect to its destination".

I use it in my custom module, in fact without any params, but i think it should work also with params. Maybe just you will have to use different alias name than your module... (not sure about it)

Baobaz
http://www.baobaz.com

H-Works Agency

Wednesday 15 July 2009 3:21:20 am

I tried andre's way and its perfect for what i need...the only problem is that you can't add new module views to the module after that.

I thought about using url_translation module, i am gonna test it to see if it works with wildcards.

Thanx

EZP is Great