2015-09-05 54 views
-2

最近我的客戶要求我將他的公司的網絡應用程序移動到另一個託管服務提供商。我已經移動了ftp文件,導入的數據庫和更改了新數據庫的參數。但它不起作用返回我「500」錯誤。看來utf8編碼有問題,但我不知道如何解決它。我不是程序員。我只知道這個應用程序是在symfony中完成的。有些東西可行,您可以登錄並查看發票等,但不能創建新的發票。Symfony 500轉移到其他服務器

http://imgur.com/a/dktBt

編輯:

我發現了一個功能,做錯誤;

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; 
} 

我能做些什麼才能使它工作?

+0

你是否也拷貝了'.htaccess'?有AddCharset UTF-8嗎?!?應該。 – loveNoHate

+1

首先查看新數據庫的字符集。以下是一些可能會爲您提供一些線索的答案:http://stackoverflow.com/questions/10205722/json-encode-invalid-utf-8-sequence-in-argument –

+0

.htacces看起來像這樣: 「##默認.htaccess文件 」這就是所有 –

回答

0

我開創的地方是:

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

改變了這個:

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; 
    } 

這樣:

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; 
    } 

問題就迎刃而解了。

相關問題