Varibles in moodle

Varibles in moodle

by Nuno Sousa -
Number of replies: 2
Hi,

I've managed to start developing a new module, and I already found howto do some nice things. :P

Creating functions and so on.

But, now I face another question that at least looks simples, but I can't solve it.

The thing is, in the file mod_form.php I have this line of code:

class mod_ontheweb_mod_form extends moodleform_mod {
function definition() {
...
$mform->addElement('text', 'ipcliente', ' IP do cliente', get_string('ipcliente'));
$mform->setType('ipcliente', PARAM_TEXT);
$mform->addRule('ipcliente', null, 'required', null, 'client');

And now, I want to read the "ipcliente" variable in view.php or lib.php.
The question is, how do I access that variable?
Average of ratings: -
In reply to Nuno Sousa

Re: Varibles in moodle

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
First, in mod/ontheweb/lib.php file, you should have add_instance and update_instance functions where you read the data from the form, and store it to your mdl_ontheweb database table.

So the question you should be asking is in view.php, how do you access the ipcliente column from the database row, and the answer is easy. At the top of view.php, you will probably have code, very similar to the code for other modules, e.g. http://cvs.moodle.org/moodle/mod/quiz/view.php?view=markup. In your case, the critical code will be $ontheweb = get_record('ontheweb', 'id', $cm->instance);. Then you can access the value you want as $ontheweb->ipcliente.
In reply to Tim Hunt

Re: Varibles in moodle

by Nuno Sousa -
Hi,

First,
thank you for your time to answer to my question, and sorry for this late follow up.

Second,
if, you can, please explain to me, step by step:
  • where and how should I declare the variable "ipcliente"?
  • how should I store information filled in by the user in it?
  • how can I access the information in it?
Thanks for your time and help.