我试图配置奏鸣曲管理员捆绑包,但我有这个错误:
尝试加载课程" ProductAdmin"从命名空间 "管理\ AdminBundle \管理员&#34 ;.你忘记了"使用"声明 另一个命名空间?
受保护的函数getSonata_Admin_ProductService() { $ instance = new \ Admin \ AdminBundle \ Admin \ ProductAdmin(' sonata.admin.product', ' Admin \ AdminBundle \ Entity \ Product',' SonataAdminBundle:CRUD'); $实例 - > setTranslationDomain(' AdminAdminBundle&#39); $ instance-> setFormTheme(array(0 =>' SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig'));
有人知道如何解决这个错误?
谢谢
Config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: @AdminAdminBundle/Resources/config/admin.yml }
# app/config/config.yml
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
Admin.yml
services:
sonata.admin.Product:
class: Admin\AdminBundle\Admin\ProductAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Product" }
arguments:
- ~
- Admin\AdminBundle\Entity\Product
- ~
calls:
- [ setTranslationDomain, [AdminAdminBundle]]
ProductAdmin.php
<?php
// src/Acme/DemoBundle/Admin/PostAdmin.php
namespace Admin\AdminBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class ProductAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('title', 'text', array('label' => 'Post Title'))
->add('author', 'entity', array('class' => 'Admin\AdminBundle\Entity\Product'))
->add('body') //if no type is specified, SonataAdminBundle tries to guess it
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('title')
->add('author')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('title')
->add('slug')
->add('author')
;
}
}
AdminAdminExtension.php
<?php
namespace Admin\AdminBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AdminAdminExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('admin.yml');
}
}
autoload.php
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* @var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
答案 0 :(得分:1)
该错误表示您的类文件无法正确自动加载。检查命名空间是否与您的路径匹配,如果有疑问,请在项目的根目录中添加一个文件,加载该类以检查自动加载配置是否有效:
<?php
require_once 'vendor/autoload.php';
var_dump(class_exists('a\b\c'));
您的源文件声明了另一条路径而不是命名空间结构这一事实表明您的类位于错误的位置。