回答

11

您需要啓用您正在使用的所有聽衆。在這種情況下,可排序。

在config.yml,添加:

stof_doctrine_extensions: 
    default_locale: en_US 
    orm: 
     default: 
      sortable: true 
+0

這是否能夠在所有捆綁排序(所以從我的回答引導方法的代碼不再neccesary?) – loostro

+0

是它。如果您使用不帶Stof包的Sortable擴展,則可以在引導方法中使用代碼。 stof捆綁爲你做代碼。 – Malcolm

+0

然後我將你的答案標記爲已接受,因爲它好得多。 – loostro

0

爲了使用可排序的行爲,你需要一個事件偵聽器添加到您的包的引導方法

<?php 

namespace Acme\DemoBundle; 

use Symfony\Component\HttpKernel\Bundle\Bundle; 

class AcmeDemoBundle extends Bundle 
{ 
    public function boot() 
    { 
     // get the doctrine 2 entity manager 
     $em = $this->container->get('doctrine.orm.default_entity_manager'); 

     // get the event manager 
     $evm = $em->getEventManager(); 
     $evm->addEventSubscriber(new \Gedmo\Sortable\SortableListener); 
    } 
} 
相關問題