t_bergman Posted February 9, 2015 Report Posted February 9, 2015 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, Quote
Tom Posted February 9, 2015 Report Posted February 9, 2015 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. Quote
MaciejO Posted February 9, 2015 Report Posted February 9, 2015 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". 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... Quote
t_bergman Posted February 9, 2015 Author Report Posted February 9, 2015 I think I have a bad cake , cause I have way too much php code in my views. I'll work on it tonight and see what I can come up with. Thanks, Quote
t_bergman Posted February 16, 2015 Author Report Posted February 16, 2015 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. Quote
Tom Posted February 16, 2015 Report Posted February 16, 2015 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. Quote
t_bergman Posted February 16, 2015 Author Report Posted February 16, 2015 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. Quote
freshJet Posted February 17, 2015 Report Posted February 17, 2015 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. Quote
t_bergman Posted February 17, 2015 Author Report Posted February 17, 2015 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. Quote
freshJet Posted February 17, 2015 Report Posted February 17, 2015 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"); ?> Quote
t_bergman Posted February 17, 2015 Author Report Posted February 17, 2015 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. Quote
t_bergman Posted February 18, 2015 Author Report Posted February 18, 2015 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 iframe method Quote
Tom Posted February 18, 2015 Report Posted February 18, 2015 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. 1 Quote
freshJet Posted February 18, 2015 Report Posted February 18, 2015 ^ What Tom said. Apply Courier to it. It will work better than an iframe. If you want to see why, try looking at it on different resolutions. Quote
t_bergman Posted April 5, 2015 Author Report Posted April 5, 2015 Got all of this working, definitely the way to go. I switched data providers and I am parsing an XML file instead. Thanks for all the help. Quote
t_bergman Posted April 5, 2015 Author Report Posted April 5, 2015 (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 April 6, 2015 by t_bergman Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.