【问题标题】:Symfony 500 on move to other serverSymfony 500 移动到其他服务器
【发布时间】:2015-12-01 13:43:34
【问题描述】:

最近我的客户要求我将他公司的网络应用程序转移到另一个托管服务提供商。我已经移动了 ftp 文件,导入了数据库并更改了新数据库的参数。但它根本无法返回“500”错误。 utf8 编码似乎有问题,但我不知道如何修复它。我不是程序员。我只知道这个应用程序是用 symfony 制作的。有些事情可行,您可以登录并查看发票等,但不能创建新发票。

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

我该怎么做才能让它发挥作用?

【问题讨论】:

  • 您是否也复制了.htaccess?里面有AddCharset UTF-8吗?!?应该是。
  • 首先查看新数据库的字符集。这是一个带有一些答案的问题,可能会为您提供一些线索:stackoverflow.com/questions/10205722/…
  • .htacces 看起来像这样:"## Default .htaccess file" 仅此而已
  • 我的第一个问题是为什么你在处理你不理解的事情吗?此外,您的数据库似乎需要使用 UTF-8 编码。您将需要删除数据库,使用正确的编码再次创建它,然后从旧服务器导入数据库。此外,您还必须确保已使用 UTF-8 完成备份!

标签: symfony


【解决方案1】:

我发现它在哪里:

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

问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 2016-09-14
    • 2017-12-08
    相关资源
    最近更新 更多