开发者

Country drop down list output to view

I have a Country list helper implemented just fine and can select quite happily.

The one thing I am trying to work out now is how to output the selected country to view...

Sample of the helper:

class CountryListHelper extends FormHelper { 

    var $helpers = array('Form'); 

function select($fieldname) {
$list = $this->Form->input($fieldname , array(
    'type' => 'select', 'label' => 'Country of Residence', 'options' => array(
        '' =>   'Please select a country',
        'AF' => 'Afganistan',
        'AL' => 'Albania',
        'DZ' => 'Algeria',
        'AS' => 'American Samoa',
        'AD' => 'Andorra', 
        'AO' => 'Angola',
        'AI' => 'Anguilla',
        'AQ' => 'Antarctica',

code in the edit and add view:

echo $this->CountryList->select('country');

The data being stored is only the acronym (as shown in the helper code snippet) and this is what is being output to view.ctp (AF for example). Is there a way to do a retrieval from the helper to match the full country name to the acronym and push it to view.ctp?

Snippet from view.ctp which I am trying to modify to display the full country name as apposed to just the ac开发者_JAVA百科ronym.

<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Country of Residence'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php echo $user['User']['country']; ?>
            &nbsp;
        </dd>

Many thanks in advance!


class CountryListHelper extends AppHelper { 
   var $helpers = array('Form'); 
   var $countries = array(
    'AF' => 'Afganistan',
    'AL' => 'Albania',
    'DZ' => 'Algeria',
    ...)
function getCountry($country){
   return $this->countries[$country]; 
}
function select($fieldname){
   $list = $this->Form->input($fieldname , array(
   'type' => 'select', 'label' => 'Country of Residence', 'options' => $countries)

call from view:

echo $this->CountryList->getCountry($user['User']['country']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜