Jump to content

Recommended Posts

Posted

I am in the process of creating my own dashboard module, a couple of quick questions.

Does all of the php code need to be the module/module.php file? Or can most of the code be placed in the template/template.php file?

I'm currently trying to figure out why a form of my is not working, when the form is processed the browser moves onto the process page url but the actual content does not change. Why would this be happening?

Thanks,

Posted

You should put your code where it is appropriate:

  • If you're fetching data you should have a class in core/common to handle database interaction.
  • If you're manipulating datasets etc to give to the template, it should be in your module.
  • If it's purely to create the view output, it should be in your template(s).

As for the issue you're seeing, it may be easier to set up another route in your module to post data to, then once you're happy everything's working you can move things around to post data to the page you want.

Posted

Hi,

1.

Because phpVMS is based on MVC (Model-View-Controller) structure you will need your handling code to be located inside modules (controllers) and classes (models). Where your template (view) files go to template folder. Just type "MVC" in Google and you should find hundreds of top notch articles about MVC as it is that popular.

Best convention I have ever heared of for MVC is "Keep Models Fat and Controllers Thin".

layercake.png

2. Possibly it is a small mistake, or a larger problem within your code. If you send me your code via private message I am more than happy to help you out.

Thanks,

Mac... :ph34r:

Posted

A small update, I've got the function "working" but I have a feeling there is a better way to do this. I have no formal php training so everything I know is from just screwing around.

The goal of this portion of the module is to be able to lookup any metar through a form on the site.

This is my dashboard_metar.php file

<?php
$url = 'http://weather.noaa.gov/pub/data/observations/metar/decoded/'. $_POST["metar"] .'.TXT';
?>
<div id="dashboardWrap">
<div id="dashboardHeader">
 <table border="1" style="width: 780px; border: 2px solid">
  <tr>
   <th style="width: 190px; text-align: center;"><a href="<?php echo SITE_URL?>/index.php/dashboard/">Crew Resource Center</a></th>
   <th style="width: 400px; text-align: center;">METAR/TAF Request</th>
   <th style="width: 190px; text-align: center;">Dispatch: Off/Online</th>
  </tr>
 </table>
 <table border="1" style="width: 780px; border: 2px solid; text-align: center;";>
  <tr>
   <td style="width: 190px;">Metar Request:</td>
   <td style="width: 400px; text-align: left;"><form action="dashboard_metar.php" method="post"><input type="text" name="metar" value="Upper Case Only" ><input type="submit" value="Submit"></form></td>
  </tr>
  <tr>
   <td colspan="2"; style="width: 780px; text-align: left;"><iframe src="<?php echo $url; ?>"; frameborder="0"; width="769px"; height="400px"; scrolling="auto";></iframe></td>
  </tr>
 </table>
</div>
</div>

This is my Dashboard.php file

<?php
//This is the Hemisphere Virtual Airlines Crew Resource Center Module
//Use of this module outside of the Hemisphere Virtual Airlines domain is prohibited
//Copyright 2013 - hphvirtual.com Administration
class Dashboard extends CodonModule {
public $title = 'C.R.C. v0.0.1';

public function index()
{
 if(!Auth::LoggedIn())
 {
  $this->set('message', 'You must be logged in to access this feature!');
  $this->render('core_error.php');
  return;
 }
  $this->render('dashboard/dashboard.php');
  $userinfo = Auth::Displayname();
}
public function metar()
{
 if(!Auth::LoggedIn())
 {
  $this->set('message', 'You must be logged in to access this feature!');
  $this->render('core_error.php');
  return;
 }
 {
  $this->render('dashboard/dashboard_metar.php');
 }
}
}

Thanks for any help or comments on this. Right now the module displays a 404 error when its first brough up, which I'm not too thrilled about but hopefully with a php if statement I can get that figured out.

Posted

You can use the following to check whether they've arrived after posting the form:

if($_POST){
...
}

So I imagine you'll probably want to put your $url = ... and your iframe inside that.

Also btw you ought to remove those semicolons there outside of the style="" attribute, and for best browser compatibility you should set height/width attributes using unitless values (i.e. height="400" rather than height="400px") - IE will sometimes have a strop and make things the wrong size.

Posted

You can use the following to check whether they've arrived after posting the form:

if($_POST){
...
}

So I imagine you'll probably want to put your $url = ... and your iframe inside that.

Also btw you ought to remove those semicolons there outside of the style="" attribute, and for best browser compatibility you should set height/width attributes using unitless values (i.e. height="400" rather than height="400px") - IE will sometimes have a strop and make things the wrong size.

Thank you very much, the "if" statement was the script needed.

Posted

Can I suggest using file_get_contents() rather than an iframe, much more practical. Of course, I assume the METAR is on a blank page by itself.

I'm not sure how I would implement that. The iframe's source is http://weather.noaa.gov/pub/data/observations/metar/decoded/KAPF.TXT and the station identifier changes based on what the user submits in the form.

I would agree with you that the 0 iframes is the perfect number of iframes to have.

Posted

Very simple.

<?php
$icao = $_POST['icao'];
echo file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
?>

You can remove the time and date if you want:

<?php
$icao = $_POST['icao'];
$metar = file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
$break = explode("/n", $metar);
echo $break[0];
?>

That's just for the METAR, if you really want that decoded part then all you need to do is modify the URL like this:

<?php
$icao = $_POST['icao'];
echo file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/decoded/stations/$icao.TXT");
?>

Posted

Very simple.

<?php
$icao = $_POST['icao'];
echo file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
?>

You can remove the time and date if you want:

<?php
$icao = $_POST['icao'];
$metar = file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
$break = explode("/n", $metar);
echo $break[0];
?>

That's just for the METAR, if you really want that decoded part then all you need to do is modify the URL like this:

<?php
$icao = $_POST['icao'];
echo file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/decoded/stations/$icao.TXT");
?>

Thank you very much, I will play around with this tonight and report back.

Posted

I've got some work to do with file_get_contents, I like that fact that I should be able to turn parts of the data into variables and mold them into more useful information than just a metar. But I'll have to design the data as right now the iframe looks better than the file_get_contents method.

php method

file_get.jpg

iframe method

iframe1.jpg

iframe2.jpg

Posted

If you wrap the file_get_contents method in a <pre> (to preserve the line breaks) and add some CSS for font style etc you should get the same result.

  • Like 1
  • 1 month later...
Posted (edited)

Just one question, I am parsing the XML and sometimes the sky condition <sky_condition sky_cover="FEW" cloud_base_ft_agl="3500"/> appears more than once depending on the weather. How can I get each item to show up.

Example

<sky_condition sky_cover="FEW" cloud_base_ft_agl="3500"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="4200"/>

Returned as two different arguments(not sure if this is the right term).

My code which is what is parsing it.

<?php echo $filecontents->data->METAR->sky_condition[sky_cover];?> at <?php echo $filecontents->data->METAR->sky_condition[cloud_base_ft_agl] ;?>

And I am loading the $filecontents variable with

$filecontents = simplexml_load_file("https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=$icao&hoursBeforeNow=1");

EDIT: Figured it out.

Edited by t_bergman

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...