How to obtain module id inside module function

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
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

How to obtain module id inside module function

Post by piotrekkr »

Hi! I want to obtain module id in function in ModuleName.module.php file. Some example:

Code: Select all

...........
function CreateDatesLink($student_id){
//$id = ??           don't know how get id of this module
return $this->CreateLink($id, 'show_profile', $this->GetPageId('dates'), '', array('student_id' =>$student_id), '', true);
}
........
I don't know how to get id of module within this function is written. I use this function in my other module. Maby someone know? Please help :)

PS sorry for my poor english
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to obtain module id inside module function

Post by calguy1000 »

The ID is created before each action method is called, so it will be valid in your method.xxxxxx.php files.  You need to pass this value into your CreateDatesLink method.

i.e: 

function CreateDatesLink($id,$student_id) {...}
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.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: How to obtain module id inside module function

Post by piotrekkr »

Ok but I want to use this function in another module that has diffrent id so I can't do it like you said.

Code: Select all

$module = $this->GetModuleInstance('Dates');
$link = $module->CreateDatesLink($student_id);
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to obtain module id inside module function

Post by calguy1000 »

I do this all the time, and doing as I suggested will work.
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.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: How to obtain module id inside module function

Post by piotrekkr »

So if I use id from other module it won't matter? May I use random id and i will be ok?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to obtain module id inside module function

Post by calguy1000 »

No, you can't use a random id..... the id is used to know which form that the control belongs to.  and it increases each time a module action is called on a particular page.
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.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: How to obtain module id inside module function

Post by piotrekkr »

So if I use id from other module it will be controlled by this other module? But I want open new page in web browser with action from Dates module and I want it to be controlled by Dates module. How I should do it if i don't know Dates module ID?
Post Reply

Return to “Developers Discussion”