简体   繁体   中英

How to use the SonataAdminBundle

I'm new to Symfony and I'm trying to create a database interface using Sonata and Doctrine ORM. At first, I`ve read this tutorial and after a few days it all start working on my VirtualBox machine Ubuntu server.

Now, I`m trying to use the sonata admin in another bundle.

So, I`ve got my SonataAdminBundle here:

/var/www/Symfony/testsonata/src/Application/Sonata

And new bundle here:

/var/www/Symfony/testsonata/src/Application/MyDbBundle

I m trying to use [this man](http://symfonydev.ru/symfony-back-and-front-interfaces/) (it s on russian).

Next, after I ve got working Sonata, I m created a new bundle:

$ php app/console generate:bundle --namespace=Application/MyDbBundle

You are going to generate a "Application\MyDbBundle\MyDbBundle" bundle
in "/var/www/Symfony/testsonata/src/" using the "annotation" format.

Then, I ran the following commands:

$ php app/console doctrine:mapping:import MyDbBundle xml --filter=Link
writing /var/www/Symfony/testsonata/src/Application/MyDbBundle/Resources/config/doctrine/Link.orm.xml

$ php app/console doctrine:generate:entities --path="/var/www/Symfony/testsonata/src" MyDbBundle:Link

Generating entities for namespace "Application\MyDbBundle\Entity\Link"
  > backing up Link.php to Link.php~
  > generating Application\MyDbBundle\Entity\Link

And the last thing I was trying to do, is to create an Administrative class and a Service description

I have created this file /var/www/Symfony/testsonata/src/Application/MyDbBundle/Admin/LinkAdmin.php which contains:

<?php
namespace Application\MyDbBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Knp\Menu\ItemInterface as MenuItemInterface;
use My\DbBundle\Entity\Link;

class LinkAdmin extends Admin
{
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper->add('title')
                      ->add('url');
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper->addIdentifier('title')
                   ->add('url')
                   ->add('updatedAt');
    } 

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('title')
                   ->add('url')
                   ->add('annotation');
    }
}

And I added this to my services.xml :

<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
      <service id="sonata.admin.my.db.link" class="Application\MyDbBundle\Admin\LinkAdmin">
            <tag name="sonata.admin" manager_type="orm" group="Databases" label="Links"/>
            <argument/>
            <argument>Application\MyDbBundle\Entity\Link</argument>
            <argument>SonataAdminBundle:CRUD</argument>
        </service>
    </services> 
</container>

When I go to

http://localhost/Symfony/testsonata/web/app_dev.php/admin/dashboard

I get this message:

InvalidArgumentException: [ERROR 94] Validation failed: no DTD found ! (in n/a - line 5, column 20) [ERROR 5] Extra content at the end of the document (in n/a - line 22, column 1)

What am I doing wrong?

According to the error, something went wrong with your xml config file. Why is there an <argument/> at the begining? It might be the problem.

PS: I mean, does this <argument></argument> works better?

or maybe i need to make another paths? because MyDbBundle and Sonata is in the different directories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM