0

我通过本教程学习 SonataAdminBundle: http ://sftuts.com/doc/jobeet/en/the-admin-generator

但不是:

在此处输入图像描述

我有空值:

在此处输入图像描述

同样在表单中,我只有提交按钮,但是如果单击此按钮,则会出现错误:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'type' cannot be null

SonataAdminBundle 的教程可能更好吗?

编辑:

<?php

//src/SfTuts/JobeetBundle/Admin/CategoryAdmin.php

namespace SfTuts\JobeetBundle\Admin;

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

class CategoryAdmin extends Admin
{
    protected $list = array(
        'id' => array('identifier' => true),
        'name',
    );
    protected $form = array(
        'name',
    );
    protected $filter = array(
        'name',
    );
}
4

1 回答 1

1

你可以阅读这篇文档。您的教程版本可能已过时。 http://sonata-project.org/bundles/admin/master/doc/index.html

试试这个代码:

use Sonata\AdminBundle\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
class CategoryAdmin extends Admin
{
    /**
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
     * @return void
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name')
            ;
    }

    /**
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
     * @return void
     */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name');
    }

    /**
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
     * @return void
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('id')
            ->addIdentifier('name');
    }
}
于 2012-05-30T11:28:36.337 回答