[英]How to use the SonataAdminBundle
I'm new to Symfony and I'm trying to create a database interface using Sonata and Doctrine ORM. 我是Symfony的新手,正在尝试使用Sonata和Doctrine ORM创建数据库接口。 At first, I`ve read this tutorial and after a few days it all start working on my VirtualBox machine Ubuntu server.
最初,我已经阅读了本教程 ,几天后,所有这些都开始在我的VirtualBox计算机Ubuntu服务器上工作。
Now, I`m trying to use the sonata admin in another bundle. 现在,我正在尝试在另一个捆绑软件中使用Sonata管理员。
So, I`ve got my SonataAdminBundle here: 所以,我在这里得到了SonataAdminBundle:
/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). 我
m trying to use [this man](http://symfonydev.ru/symfony-back-and-front-interfaces/) (it
俄语)。
Next, after I ve got working Sonata, I
m created a new bundle: 接下来,在
ve got working Sonata, I
创建了一个新的捆绑包:
$ 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: 我已创建此文件
/var/www/Symfony/testsonata/src/Application/MyDbBundle/Admin/LinkAdmin.php
,其中包含:
<?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
: 并将其添加到我的
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 !
InvalidArgumentException:[错误94]验证失败:未找到DTD! (in n/a - line 5, column 20) [ERROR 5] Extra content at the end of the document (in n/a - line 22, column 1)
(在n / a-第5行,第20列中)[错误5]文档末尾的多余内容(在n / a-22行,第1列中)
What am I doing wrong? 我究竟做错了什么?
According to the error, something went wrong with your xml config file. 根据错误,您的xml配置文件出了点问题。 Why is there an
<argument/>
at the begining? 为什么一开始会有
<argument/>
? It might be the problem. 可能是问题所在。
PS: I mean, does this <argument></argument>
works better? PS:我的意思是,此
<argument></argument>
效果更好吗?
or maybe i need to make another paths? 还是我需要另辟paths径? because MyDbBundle and Sonata is in the different directories
因为MyDbBundle和Sonata在不同的目录中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.