Welcome Guest, Not a member yet? Register   Sign In
"Notice" in my lib, xml trouble
#1

[eluser]Unknown[/eluser]
sorry for my bad(very bad) english

i have controller

Code:
<?php

class Main extends Controller {

    function Main()
    {
        parent::Controller();    
    }
    
    function index() {
              $this->load->library('weather');
              echo $this->weather->getWeather(1310);
    }
}
?>
and simple library
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Weather {

    function Weather() {
        $this->CI =& get_instance();
    }

    public function getWeather($city) {
          $xmlstr = @join('',file('http://weather.co.ua/xml/feed.xml?version=1.1&city;='.intval($city).'&dayf=5'));
          $xml = new SimpleXMLElement($xmlstr);
      
          for($i=0;$i<24;$i++) {
            $xmlpath = $xml->forecast->day[$i];
            $cloud = $xmlpath->cloud;
            $pict = $xmlpath->pict;
            $ppcp = $xmlpath->ppcp;
            $tmin = $xmlpath->t->min;
            $tmax = $xmlpath->t->max;
            $pmin = $xmlpath->p->min;
            $pmax = $xmlpath->p->max;
            $wmin = $xmlpath->wind->min;
            $wmax = $xmlpath->wind->max;
            $wrumb = $xmlpath->wind->rumb;
            $hmin = $xmlpath->hmid->min;
            $hmax = $xmlpath->hmid->max;
            $wpi = $xmlpath->wpi;
            $city = intval($city);
          }
    }

}

?&gt;

whis work! but on every line whith "$xmlpath->..." i have per line for two similar errors

Quote:A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/Weather.php
Line Number: 22 <- every line whith "$xmlpath->..."

what is wrong?
#2

[eluser]avinashv[/eluser]
Going from your code, you are trying to access the XML feed at "http://weather.co.ua/xml/feed.xml?version=1.1&city;=1310&dayf=5"

If you go there, you get an error "XML001 Main input params not found". The reason the XML parser is throwing you an error is because the DOM tree doesn't exist. Fix your feed link and that should sort problems out.
#3

[eluser]Seppo[/eluser]
The problem I'm getting is that the xml only has 20 days, so after that the xml is empty =)

Try replacing
Code:
for($i=0;$i<24;$i++) {

for
Code:
$times = count($xml->forecast->day);
for($i=0;$i<$times;$i++) {

@avinashv: I think it is city= and not city;=... probably a forum problem
#4

[eluser]Unknown[/eluser]
big thanks Seppo, it's work ^^




Theme © iAndrew 2016 - Forum software by © MyBB