0

I have following code in my controller:

$model=new MForm;
    $list=MForm::model()->findAllBySql('SELECT form_name FROM m_form');
    var_dump($list);

It returns values of form_name(values are integer e.g 1, 2, 3 etc.) I created const in my controller:

    const US=1;
    const Ru=2;

I need to show const names such as Ru instead of 2 in my view file when it 2(US instead of 1). How can I do it?

2 Answers2

0

Define an array that contains all the constant in it like:

$const = [
  1 => 'US',
  2 => 'RU'
  // and so on
];

and use it like:

echo $const[$result['col_name']];

here $result contains the result of query and col_name is the column that returns 1,2,3 and so on.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

Inside view put it inside a html element without any display Statement of PHP.

Hope it will work...

Deepak swain
  • 3,380
  • 1
  • 30
  • 26