Page 1 of 1

How to obtain module id inside module function

Posted: Tue Jan 15, 2008 2:30 pm
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

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 2:35 pm
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) {...}

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 3:36 pm
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);

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 3:45 pm
by calguy1000
I do this all the time, and doing as I suggested will work.

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 6:24 pm
by piotrekkr
So if I use id from other module it won't matter? May I use random id and i will be ok?

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 6:26 pm
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.

Re: How to obtain module id inside module function

Posted: Tue Jan 15, 2008 6:57 pm
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?