Last active
December 17, 2015 03:29
-
-
Save arturmamedov/5543580 to your computer and use it in GitHub Desktop.
Changes for work in Smarty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.php.net/manual/en/function.timezone-identifiers-list.php | |
<?php | |
// here we are in to a script php how send the variable with array to smarty | |
$zones = timezone_identifiers_list(); | |
foreach ($zones as $zone) | |
{ | |
$zoneExploded = explode('/', $zone); // 0 => Continent, 1 => City | |
// Only use "friendly" continent names | |
if ($zoneExploded[0] == 'Africa' || $zoneExploded[0] == 'America' || $zoneExploded[0] == 'Antarctica' || $zoneExploded[0] == 'Arctic' || $zoneExploded[0] == 'Asia' || $zoneExploded[0] == 'Atlantic' || $zoneExploded[0] == 'Australia' || $zoneExploded[0] == 'Europe' || $zoneExploded[0] == 'Indian' || $zoneExploded[0] == 'Pacific') | |
{ | |
if (isset($zoneExploded[1]) != '') | |
{ | |
$area = str_replace('_', ' ', $zoneExploded[1]); | |
if (!empty($zoneExploded[2])) | |
{ | |
$area = $area . ' (' . str_replace('_', ' ', $zoneExploded[2]) . ')'; | |
} | |
$locations[$zoneExploded[0]][$zone] = $area; // Creates array(DateTimeZone => 'Friendly name') | |
} | |
} | |
} | |
$this->view->time_zone = $locations; // here i send the array to view where i hava Smart Tamplater | |
?> | |
/*** Smarty in View ***/ | |
<p> | |
<label for="timeZone">Timezone: </label> | |
<select required id="timeZone" name="time_zone"> | |
<option value="">Default @todo</option> | |
{foreach from=$time_zone item=ntz key=ktz} | |
<optgroup label='{$ktz}'>{$ktz} | |
{foreach from=$time_zone[$ktz] item=timezone key=ktimezone} | |
{assign var='selected' value=''} | |
{if $timezone == $fp->time_zone} | |
{assign var='selected' value='selected="selected"'} | |
{/if} | |
<option {$selected} value="{$ktimezone}">{$timezone}</option> | |
{/foreach} | |
</optgroup> | |
{/foreach} | |
</select> | |
{include file='lib/error.tpl' error=$fp->getError('time_zone')} | |
</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment