我正在关注有关安装Sonata Admin Bundle的文档。我在步骤'Creating an Admin'中遇到了问题。 我有以下错误:
预计在文件中找到“AppBundle \ Admin \ CategoryAdmin”类 “[...] / src目录/的appbundle /管理/ CategoryAdmin.php” 从资源“../../src/AppBundle/*”导入服务时,但它 没找到!检查资源中使用的名称空间前缀 [...] /应用/配置/ services.yml (正在从中导入 “[...] /应用/配置/ config.yml”)。
我已经创建了“类别管理类”
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib as mpl
并将它们设置为config.yml
<?php
// src/Admin/CategoryAdmin.php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class CategoryAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name', TextType::class);
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('name');
}
}
这条路线正在运行,所以我不会发布它。
我的项目就像您在屏幕截图中看到的那样构建:
那么我是如何构建项目或者我在配置文件上做某事有问题吗? 我试图复制/粘贴文件名,以防问题来自文件名,但它改变了任何东西。有什么想法吗?
答案 0 :(得分:0)
您的名称空间不正确,从错误和初看的角度来看。
检查以下代码。
<?php
namespace AppBundle\Admin; # CHANGE THIS LINE TO FOLLOWING!
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class CategoryAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name', TextType::class);
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('name');
}
}
和服务
services:
# ...
admin.category:
class: AppBundle\Admin\CategoryAdmin # fix here
arguments: [~, AppBundle\Entity\Category, ~] # and here
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
public: true