Jump to content

Getting variable from template into class / module


CedGauche

Recommended Posts

Good morning from germany,

I've created a new module with a form. But how can I get the form values as a variable into the DataClass query.  The module has these 3 files:

TourenDataClass.php

Touren.php

touren.tpl

 

queries without variables from the TourenDataClass.php are working in the touren.tpl.

 

I'm quity new in php so I need advice ;)

 

Edited by CedGauche
Link to comment
Share on other sites

On 9/11/2019 at 11:59 AM, CedGauche said:

Good morning from germany,

I've created a new module with a form. But how can I get the form values as a variable into the DataClass query.  The module has these 3 files:

TourenDataClass.php

Touren.php

touren.tpl

 

queries without variables from the TourenDataClass.php are working in the touren.tpl.

 

I'm quity new in php so I need advice ;)

 

Hello, greetings from India :)

[Quick fix, change your file name to TourenData.class.php] 
Assuming you are asking how to get data into the DataClass, the answer to that would be "using SQL". 

Example: 
 

public static function GetTourenData() {

// Getting all values from a table 
$sql = "SELECT * FROM `phpvms_tourendata`";
return DB::get_results($sql);
}


If you need to use a variable in the module, assuming that it is already establed (coded) in the DataClass (core/common) folder, all you'll have to do is to just assign a variable to display the value. 

Example: 
In ACARSData.class.php, you have a static function called "GetACARSData()" which returns an array. The idea is to get your static function inside TourenData.class.php to return some value. Once that is done, you can call that inside your module like this... 

Assuming we are coding in the public index function of your module, code this way 

$this->set('tourendata', TourenData::GetTourenData()); 
$this->render('touren.tpl');


So now, phpVMS is assigning the values of TourenData::GetTourenData() function into a variable called "$tourendata" which you can use in the template file. 
One more way I have seen people using this is, to set the data to the variable instead of using "this", 
 

Template::set('tourendata', TourenData::GetTourenData()); 



nevertheless, both methods work. 

Let me know if this was of any help, 

Regards, 
Leonard
 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...