迁移前,带有ajax的CRUD SonataAdmin无法正常工作

时间:2018-09-28 17:41:42

标签: php symfony twig

对于一个使用Symfony 3.1的项目,我想向我寻求帮助,我现在更新到3.4。 O composer.json就像这样:

"require" : {
    "php" : ">=5.5.9",
    "symfony/symfony" : "3.1.*",
    "doctrine/orm" : "^2.5",
    "doctrine/doctrine-bundle" : "^1.6",
    "doctrine/doctrine-cache-bundle" : "^1.2",
    "symfony/swiftmailer-bundle" : "^2.3",
    "symfony/monolog-bundle" : "^2.8",
    "symfony/polyfill-apcu" : "^1.0",
    "sensio/distribution-bundle" : "^5.0",
    "sensio/framework-extra-bundle" : "^3.0.2",
    "incenteev/composer-parameter-handler" : "^2.0",
    "symfony/form" : "^3.1.0",
    "twbs/bootstrap" : "^3.3",
    "symfony/assetic-bundle" : "^2.8",
    "components/jquery" : "^3.0",
    "sonata-project/admin-bundle" : "^3.3",
    "sonata-project/doctrine-orm-admin-bundle" : "^3.0",
    "jms/serializer-bundle" : "^1.1",
    "friendsofsymfony/jsrouting-bundle" : "2.0.0-alpha1",
    "friendsofsymfony/user-bundle" : "dev-master#c62c727dc7a387edc16df32d2ee4181e620ad35f",
    "setasign/fpdf" : "1.8.1",
    "knplabs/knp-snappy-bundle" : "^1.4",
    "knplabs/knp-paginator-bundle" : "2.5.3",
    "endroid/qrcode" : "^1.9"
}

我改为:

"require" : {
    "php" : ">=7.2",
    "symfony/symfony" : "3.4.*",
    "doctrine/orm" : "^2.6",
    "doctrine/doctrine-bundle" : "^1.9",
    "doctrine/doctrine-cache-bundle" : "^1.3",
    "symfony/swiftmailer-bundle" : "^3.2",
    "symfony/monolog-bundle" : "^3.3",
    "symfony/polyfill-apcu" : "^1.9",
    "sensio/distribution-bundle" : "^5.0",
    "sensio/framework-extra-bundle" : "^5.0.2",
    "incenteev/composer-parameter-handler" : "^2.1",
    "symfony/form" : "^3.4",
    "twbs/bootstrap" : "^4.1",
    "symfony/assetic-bundle" : "^2.8",
    "components/jquery" : "^3.3",
    "sonata-project/admin-bundle" : "^3.39",
    "sonata-project/doctrine-orm-admin-bundle" : "^3.6",
    "jms/serializer-bundle" : "^2.4",
    "friendsofsymfony/jsrouting-bundle" : "2.2.0",
    "friendsofsymfony/user-bundle" : "^2.1",
    "setasign/fpdf" : "1.8.1",
    "knplabs/knp-snappy-bundle" : "^1.5",
    "knplabs/knp-paginator-bundle" : "^2.8",
    "endroid/qrcode" : "^1.9"
}

但是失败发生了多长时间才能访问使用ajax的奏鸣曲表格: 找不到模板“”(已查看:/ var / www / html / dhui / vendor / knplabs / knp-menu / src / Knp / Menu / Resources / views,/ var / www / html / dhui / app / Resources /视图,/ var / www / html / dhui / vendor / symfony / symfony / src / Symfony / Bridge / Twig / Resources / views / Form)。

故障发生在具有此功能的位置:

class TesteAdmin extends AbstractAdmin
{
/**
 * Altera o template padrão do admin para o template com AJAX
 */
public function getTemplate($name)
{ dump($this->templates); exit;
    if (isset($this->templates[$name])) {
        if ($name === 'edit') {
            return 'TesteBundle:Anotacao:base_edit.html.twig';
        } else {
            return $this->templates[$name];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

人们

要解决此问题,我做了以下事情:

class TesteAdmin extends AbstractAdmin
{
    public function getTemplate($name)
    { 
        if ($name === 'edit') {
           return 'TesteBundle:Anotacao:base_edit.html.twig';
        } else {
           return parent :: getTemplate($name);
        }
    }
}