0

我正在尝试使用 SonataAdminBundle 来启动和运行一些后端管理功能,但我的第一个配置类遇到了障碍。

我已将以下内容添加到 app/config/config.yml

services:
    sonata.admin.sport:
        class: Clarity\CoachTimeBundle\Admin\SportAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: General, label: Sports}
        arguments: [null, Clarity\CoachTimeBundle\Entity\Sport, null]

并在路径 src/Clarity/CoachTimeBundle/Admin/SportAdmin.php 中定义了以下类

<?
namespace Clarity\CoachTimeBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;

class SportAdmin extends Admin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name');
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name');
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name');
    }

    public function validate(ErrorElement $errorElement, $object)
    {
        $errorElement
            ->with('name')
                ->assertMaxLength(array('limit' => 255))
            ->end();
    }
}

当我尝试清除缓存并运行应用程序时,出现以下错误:自动加载器预期类“Clarity\CoachTimeBundle\Admin\SportAdmin”将在文件“src//Clarity/CoachTimeBundle/Admin/SportAdmin.php”中定义。找到文件但类不在其中,类名或命名空间可能有错字。

谢谢,安德鲁

4

0 回答 0