Capturing Line Breaks for a Site Variable

edited April 2013 in Feature Requests
Hi,

Come across a need to store line breaks in a Site Variable stored in Fuel. Would like to know the approach I should take. The use case is for storing a set of dropdown values in a Site Variable field where each value is separated by a newline or line break. I would like to pull the Site Variable down in code and then explode it in php to create an array using the newline as the separator. This array can then be used to populate the dropdown with the values in the Site Variable.

The code looks like this:

$this->load->module_model(FUEL_FOLDER, 'sitevariables_model'); $referralCodes = $this->sitevariables_model->find_one(array('name' => 'Referral Codes')); if(isset($referralCodes->value)) { $referralCodes = explode('/n', $referralCodes->value); foreach($referralCodes as $referralCode) { $referralCodes[$referralCode] = $referralCode; } return $referralCodes; }

Only problem is that it appears the MySQL text fields don't support storing newlines. Is there a way I can force newlines to be saved with a mod to Fuel, or do I have to choose a different mysql field data type? Would like to not have to go that route, since you guys have good reason for using the text field for Site Variables.

Thanks!
Erik

Comments

  • edited 7:39PM
    MySQL should be able to store the newlines. Try using double quotes and change the slash to a backslash:
    $referralCodes = explode("\n", $referralCodes->value);
  • edited 7:39PM
    Thank you for catching my error! It worked! Thanks again for the great forum support. Cheers, Erik
Sign In or Register to comment.