覆盖特定实体的base_edit_form.html.twig并创建特定操作 - 错误:无法加载类型“操作”

时间:2012-10-08 13:32:16

标签: symfony symfony-2.1 symfony-sonata

所以我有一个EmailAdmin配置来管理NewsletterBundle。

一切正常我已经有编辑,列表和显示有效的默认操作。

我查看了Vendor / SonataAdminBundle,其中是编辑/添加实体的模板(使用“创建”/“创建并添加”按钮),我找到了这个模板:“base_edit_form.html.twig”,其中包含按钮

所以我这样做:

//配置到sendemail的新路由并添加操作以配置表单字段

namespace Jade\NewsletterBundle\Admin;

use Doctrine\Common\Collections\Collection;

use Sonata\AdminBundle\Route\RouteCollection;

//use Jade\ReveBundle\Entity\Thematique;

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 EmailAdmin extends Admin
{

    protected function configureRoutes(RouteCollection $collection) {
        $collection->add('sendemail','/sendemail'); 
    }

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('objet')
            //->add('corps')
            ->add('corps', null, array('required' => false, 'attr' => array('class' => 'ckeditor')))   


            ->add('groupes')  

         ->add('groupes', 'sonata_type_model',
                           array(
                                   'by_reference' => false,
                                   'expanded' => true,
                                   'label' => 'Groupes',
                                   'compound' => true,
                                   'multiple' => true,
                           )
                   )
       ->add('_action', 'actions', array( 'actions' => array(  
        'sendemail' => array('template' =>
        'NewsletterBundle:Admin:sendemail.html.twig'),)));


    }

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

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('objet')
            ->add('corps')



        ;
    }

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

//这是我的EmailAdminBundle:

namespace Jade\NewsletterBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;


class EmailAdminController extends Controller
{
    /**
     * @Route("/sendemail")
     * @Template()
     */
    public function sendemailAction()
    {
        return $this->render('NewsletterBundle:Admin:sendemail.html.twig');
    }


}

//在NewsletterBundle / Resources / views / Admin / sendemail.html.twig

{% block form %}
Override
    {% set url = admin.id(object) ? 'edit' : 'create' %}

    {% if not admin.hasRoute(url)%}
        <div>
            {{ "form_not_available"|trans({}, "SonataAdminBundle") }}
        </div>
    {% else %}
        <form class="form-horizontal" action="{{ admin.generateUrl(url, {'id': admin.id(object), 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}" {{ form_enctype(form) }} method="POST">
            {% if form.vars.errors|length > 0 %}
                <div class="sonata-ba-form-error">
                    {{ form_errors(form) }}
                </div>
            {% endif %}

            {% block sonata_pre_fieldsets %}{% endblock %}

            {% for name, form_group in admin.formgroups %}
                <fieldset {% if form_group.collapsed %}class="sonata-ba-fielset-collapsed"{% endif %}>
                    <legend>
                        {% if form_group.collapsed %}
                            <a href="" class="sonata-ba-collapsed" title="{{ 'link_expand'|trans({}, 'SonataAdminBundle') }}">{{ name|trans({}, admin.translationdomain) }}</a>
                        {% else %}
                            {{ name|trans({}, admin.translationdomain) }}
                        {% endif %}
                    </legend>

                    <div class="sonata-ba-collapsed-fields">
                        {% for field_name in form_group.fields %}
                            {% if admin.formfielddescriptions[field_name] is defined %}
                                {{ form_row(form[field_name])}}
                            {% endif %}
                        {% endfor %}
                    </div>
                </fieldset>
            {% endfor %}

            {% block sonata_post_fieldsets %}{% endblock %}

            {{ form_rest(form) }}

            {% block formactions %}
                <div class="well form-actions">
                    {% if app.request.isxmlhttprequest %}
                        {% if admin.id(object) %}
                            <input type="submit" class="btn btn-primary" name="btn_update" value="{{ 'btn_update'|trans({}, 'SonataAdminBundle') }}"/>
                        {% else %}
                            <input type="submit" class="btn" name="btn_create" value="{{ 'btn_create'|trans({}, 'SonataAdminBundle') }}"/>
                        {% endif %}
                    {% else %}
                        {% if admin.supportsPreviewMode %}
                            <input class="btn btn-info persist-preview" name="btn_preview" type="submit" value="{{ 'btn_preview'|trans({}, 'SonataAdminBundle') }}"/>
                        {% endif %}
                        {% if admin.id(object) %}
                            <input type="submit" class="btn btn-primary" name="btn_update_and_edit" value="{{ 'btn_update_and_edit_again'|trans({}, 'SonataAdminBundle') }}"/>
                            <input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>

                            {% if admin.hasroute('delete') and admin.isGranted('DELETE', object) %}
                                {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}
                                <a class="btn btn-danger" href="{{ admin.generateObjectUrl('delete', object) }}">{{ 'link_delete'|trans({}, 'SonataAdminBundle') }}</a>
                            {% endif %}
                        {% else %}
                            <input class="btn btn-primary" type="submit" name="btn_create_and_edit" value="{{ 'btn_create_and_edit_again'|trans({}, 'SonataAdminBundle') }}"/>
                            <input class="btn" type="submit" name="btn_create_and_create" value="{{ 'btn_create_and_create_a_new_one'|trans({}, 'SonataAdminBundle') }}"/>
                      {% endif %}
                    {% endif %}
                </div>
            {% endblock formactions %}
        </form>
    {% endif%}

{% endblock %}

我有错误:无法加载类型“操作”,所以我不知道为什么我有这个错误?如果这是覆盖特定实体的特定视图的好方法吗?

感谢您的帮助

0 个答案:

没有答案