Returning nothing
Posted: Wed Feb 04, 2009 10:29 am
When I call the view helper's getCountryName('us') it doesn't return anything. No errors or anything. I'm loading the countries from a file that looks like this:
File looks like this:
Code: Select all
<?php
class Redeemed_View_Helper_GetCountryName extends Zend_View_Helper_Abstract
{
public function getCountryName($code)
{
return Redeemed_Countries::getInstance()->getCountryName($code);
}
}Code: Select all
<?php
class Redeemed_Countries
{
protected $_countries;
protected $_path;
private static $_instance;
public function getCountryName($code)
{
$countries = $this->getCountries();
return $countries[$code];
}
public function getCountries()
{
if(empty($this->_countries))
{
$file = fopen('countries.txt', 'r');
if(!$file)
while(!feof($file))
{
$line = fread($file);
list($name, $code) = split(';', $line);
$this->_countries[$code] = $name;
}
fclose($file);
}
return $this->_countries;
}
public static function getInstance()
{
if(!is_object(self::$_instance))
self::$_instance = new Redeemed_Countries();
return self::$_instance;
}
private function __construct()
{ }
private function __clone()
{ }
}Code: Select all
Afghanistan;AF
Aland Islands;AX
Albania;AL
Algeria;DZ
...