Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
JSON accented characters output failure
  • I'm trying to adapt Phil Foulston's adaptation of jQuery Autocomplete to FuelPHP. However, I have problems with the JSON Rest Controller output. I've checked that DB's charsets and Config's DB charset are in UTF8. This is my REST Controller:
    class Controller_Search extends Controller_Rest
    {
     public function get_titles()
     {
      $result = DB::select('*')->from('titles')->where('title', 'like', '%'.Input::get('term').'%'->limit(10)->as_object()->execute();
      
      $data['response'] = 'true'; //I don't know why Phil does this
      $data['message'] = array();
    
      foreach($result as $row)
      {
       $data['message'][] = array(
           'label' => $row->title,
           'value' => $row->title);
      }
    
      $this->response($data);
     }
    }
    

    BUG: IN THIS POST, "accented a", is seen as á. Accessing ".../search/titles.json?term=scan", the output changes "á" with "\u00e1":
    {"response":"true","message":[{"label":"Esc\u00e1ndalo en Bohemia","value":"Esc\u00e1ndalo en Bohemia"},{"label":"A Scandal in Bohemia","value":"A Scandal in Bohemia"}]}
    
    BUT if I print the array everything looks fine!
    Array
    (
        [response] => true
        [message] => Array
            (
                [0] => Array
                    (
                        [label] => Escándalo en Bohemia
                        [value] => Escándalo en Bohemia
                    )
    
                [1] => Array
                    (
                        [label] => A Scandal in Bohemia
                        [value] => A Scandal in Bohemia
                    )
            )
    )
    

    Any suggestion on where I'm making the mistake?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!