Best place to put a method

I have a db table named ‘question’ that has placeholders within the ‘question’ field. For example, “What is {company_x}'s price for your product?” where {company_x} will be replaced with another value.

I have a function within my Question model to replace that variable with another, however I call it within the view. For example, in my view I have:




foreach($questions as $question):

  echo Question::model()->replace_db_vars($question->question);

endforeach



I feel like this isn’t elegant nor efficient and was wondering if someone had a recommendation on how to do it better.

Can you post, code of function?

Here’s my code in the model:




public function replace_db_vars($text){

  $fixed_text = str_replace('{company_x}', Yii::app()->user->competitor, $text);

  return $fixed_text;

}



The controller does a findAll call:




$questions = Question::model()->findAll();

$this->render('survey',array(

  'questions'=>$questions

  );



The view file:




foreach($questions as $question):

  echo Question::model()->replace_db_vars($question->question);

endforeach



In your model




public function replace_db_vars(){

  $fixed_text = str_replace('{company_x}', Yii::app()->user->competitor, $this->question);

  return $fixed_text;

}

in view




foreach($questions as $question):

  echo $question->replace_db_vars();

endforeach