Can I avoid encoding on save in a model?

edited October 2014 in Modules
If I use a model to save on database a spanish world with accent "ó" it stores in database like ó (html style) but if I save the same not via model it saves: \u00f3 and I need the 2nd one because Android (client) reads fine this texts from json utf8 header sent from php.

In my database char_set I have utf8 and collation utf8_general_ci
And in the config.php I have charset 'UTF-8'

Comments

  • edited October 2014
    Ups!! in my previous post I wrote de second ó with accent in html style but it seems the forum converted it!!! (hope you understand me)
  • edited 5:44PM
    There is a property you can set on your model called "auto_encode_entities" that by default is set to TRUE which means it will convert characters like that to HTML entities. You can try setting that to FALSE, or be more specific and specify an array of only the fields you want to apply that to.
    ... public $auto_encode_entities = FALSE; ...
  • edited 5:44PM
    Great! thank you!
  • edited 5:44PM
    I was tryin to use an enum field in model for a type of registry, with values in spanish (what means I'm using accents: áéíóúñ). I was getting the invalid type error on saving because of the auto-entities-encoding.
    When I disable it for that specific field everything works fine.

    Just as a question, should this be a default behaviour for an enum? If the values are being changed on saving any not ASCII would be a problem in an enum.

    By the way, this my first time working with FUEL and I'm loving it! ;)
  • edited 5:44PM
    The $auto_encode_entities is mostly to ensure that HTML input is escaped and safe for displaying on the front end. Since that is a public property of the object the default value would need to be changed to a third option of NULL and if NULL is detected, would need to run a query to figure out the enum field types (if it hasn't already), and then dynamically apply to only those fields that are not an ENUM as an array of just those column names. It's an interesting idea, but may be a bit much to set a default value dynamically for that property.
Sign In or Register to comment.