Howto create a link to a page and give a module of the page some parameters ?

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
User avatar
ghostrifle
Forum Members
Forum Members
Posts: 54
Joined: Wed Mar 02, 2005 11:03 pm

Howto create a link to a page and give a module of the page some parameters ?

Post by ghostrifle »

Hey there,


I have something like a "preview" on the frontpage of my site. Now I want to click this preview to get to a specific page of the site and wanna give the module of this page some parameters. For now I'm doing

Code: Select all

<a href="?page=Filme">bla</a>
Well, ok so far, but I wanna give the module "MovieReview" some dynamic paramaters so that it shows directly a movie and not the whole listing. The link should look something like this:

Code: Select all

<a href="?page=Filme&movieid=666">bla</A>
So how do I do this ?? You know what I mean ??

Bye, ghostrifle
Krol

Re: Howto create a link to a page and give a module of the page some parameters ?

Post by Krol »

Hi!

I found out, that, if you would do this on your frontpage:

Code: Select all

 <a href="?page=Filme&m1movieid=666">bla</a>
and this in your module:

Code: Select all

 echo $params['movieid']; 
you probably are going to get this:

Code: Select all

666
I don't know what exactly the "m1" means, but its in the $id of the module i'm writing right now.
100rk

Re: Howto create a link to a page and give a module of the page some parameters

Post by 100rk »

ghostrifle wrote: bla
Array $params[] is used for access to params of module declaration - for example if You will declare module like {cms_module module="YourModuleName" param1="whatever"}, You can access to parameter 'param1' through $params['param1'] - I am talking about body of function DoAction() of course...

So, if You will use anchor like bla, You can access to parameter 'movieid' by PHP superglobal variable $_GET['movieid'] or $_REQUEST['movieid'].

Note: use

Code: Select all

echo '<a href="?page=Filme&movieid=666">bla</a>';
instead of

Code: Select all

echo '<a href="?page=Filme&movieid=666">bla</a>';
Last edited by 100rk on Thu Mar 10, 2005 5:33 pm, edited 1 time in total.
User avatar
ghostrifle
Forum Members
Forum Members
Posts: 54
Joined: Wed Mar 02, 2005 11:03 pm

Re: Howto create a link to a page and give a module of the page some parameters

Post by ghostrifle »

OK thanks. I thought I could use $params for getting the $_GET variables too. I tried to avoid the $_GET... well without luck ;) Now it's working with $_GET.
100rk

Re: Howto create a link to a page and give a module of the page some parameters

Post by 100rk »

ghostrifle wrote: I thought I could use $params for getting the $_GET variables too.
I am SO SORRY, I was study documentation comments right now and You are partially right - array $params contains merged params from module declaration and all items of array $_REQUEST,
BUT (!!) with prefix ($id) of this module only. This is reason what array $params don't contains those values from Your HTML anchor, because You omit this 'id-prefix' and there is no way how to reliably determine which $id will module obtain from CMSMS at other page where it will be calling from. So, this is true reason why You have to use $_GET or $_REQUEST for Your purpose. ;-)
Of course, if You create module which will be called from already loaded page or from admin, I recommend to You using of its id prefix in requests - most simple way to do this is by using functions CreateXXXX() from class CMSModule (by example: I mean 'echo $this->CreateLink(....);' of course). :-)

OR - there is best and clean way to do this - just turn this module into new content type like module News doing - page with content type 'News' is called by module 'News' from any page - and it can deliver GET parameters over different pages by 'CMSMS friendly' way.
Last edited by 100rk on Thu Mar 10, 2005 10:19 pm, edited 1 time in total.
Post Reply

Return to “Developers Discussion”