-2

Lately my client asked me to move his company's web app to another hosting provider. I've moved the ftp files, imported database and changed parameters for new db. But it simply doesn't work returning me "500" errors. It seems there is something wrong with utf8 coding but I have no idea how to fix it. I'm not a programmer. All I know that this application is made in symfony. Some things work, you can login and view invoices etc. but not create a new one.

https://i.stack.imgur.com/uAnTq.jpg

Edit:

I found a function which does error;

public function getClientsAjaxAction()
{
    $encoders = array(new XmlEncoder(), new JsonEncoder());
    $normalizers = array(new GetSetMethodNormalizer());
    $serializer = new Serializer($normalizers, $encoders);
    $user = $this->get('security.context')->getToken()->getUser();
    $clients = $this->getDoctrine()->getEntityManager()
            ->getRepository('\fh\Bundle\Entity\Client')
            ->findBy(array('companyIndex' => $user->getCompanyIndex()));
    $response = new Response($serializer->serialize($clients, 'json')); 
    $response->headers->set('Content-Type', 'application/json');
    return $response;
}

What can i do to make it work?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Mr 660
  • 51
  • 10
  • Have you copied the `.htaccess` also? Is there `AddCharset UTF-8` in it?!? Should be. – loveNoHate Sep 05 '15 at 14:56
  • 1
    Start by looking at the charset of your new database. Here's an question with a few answers that might provide you with a few leads: http://stackoverflow.com/questions/10205722/json-encode-invalid-utf-8-sequence-in-argument – Darragh Enright Sep 05 '15 at 15:04
  • .htacces looks like this: "## Default .htaccess file " and thats all – Mr 660 Sep 05 '15 at 15:58
  • My first question here would be **WHY** are you handling things you don't understand? Also, it appears your database might need to have an UTF-8 encoding. You will need to drop the db, create it again with the proper encoding and import your database from the old server. Also, you have to make sure the backup has been done using UTF-8 as well! – tftd Sep 05 '15 at 20:21

1 Answers1

0

I founds where it is:

vendor/symfony/symfony/src/Symfony/Component/Serializer/Encoder/JsonEncode.php

changed this:

public function encode($data, $format, array $context = array())
    {
        $context = $this->resolveContext($context);
        $encodedJson = json_encode($data, $context['json_encode_options']);
        $this->lastError = json_last_error();
        return $encodedJson;
    }

to this:

function changeToUtf8($data)
    {
        if(is_array($data))
        {
            foreach($data as $key =>$value)
            {
                $data[$key]=$this->changeToUtf8($value);
            }
        }
        else 
        {
            return mb_convert_encoding($data,'UTF-8','UTF-8');
        }
        return $data;
    }
    public function encode($data, $format, array $context = array())
    {
        $context = $this->resolveContext($context);
        $data=$this->changeToUtf8($data);
        $encodedJson = json_encode($data, $context['json_encode_options']);
        $this->lastError = json_last_error();
        return $encodedJson;
    }

problem solved.

Mr 660
  • 51
  • 10