@@ -67,15 +67,13 @@ The code snippets here should get you started quickly, including jQuery 3. For m
6767``` php?start_inline=true
6868use Omines\DataTablesBundle\Adapter\ArrayAdapter;
6969use Omines\DataTablesBundle\Column\TextColumn;
70- use Omines\DataTablesBundle\Controller\DataTablesTrait ;
70+ use Omines\DataTablesBundle\DataTableFactory ;
7171
7272class MyController extends Controller
7373{
74- use DataTablesTrait;
75-
76- public function showAction(Request $request)
74+ public function showAction(Request $request, DataTableFactory $dataTableFactory)
7775 {
78- $table = $this->createDataTable ()
76+ $table = $dataTableFactory->create ()
7977 ->add('firstName', TextColumn::class)
8078 ->add('lastName', TextColumn::class)
8179 ->createAdapter(ArrayAdapter::class, [
@@ -94,8 +92,8 @@ class MyController extends Controller
9492```
9593This trivial bit of code in your controller prepares a fully functional DataTables instance for use.
9694
97- The optional <code >DataTablesTrait </code > is included to expose convenience methods in your controller for
98- easy instantiation. The ` createDataTable ` function is used in this example. On the DataTable instance we
95+ The <code >DataTableFactory </code > service is injected to expose convenience methods in your controller
96+ for easy instantiation. The ` create ` function is used in this example. On the DataTable instance we
9997add 2 columns of type ` TextColumn ` , and we bind it to an adapter providing a static array as the
10098source of the data.
10199
@@ -107,11 +105,9 @@ otherwise we render a template with the table provided as a parameter.
107105
108106## Controller setup
109107
110- When using <code >DataTablesTrait</code > it is assumed that the <code >DataTableFactory</code > trait is available
111- in the controller's <code >$container</code >. When using Symfony's legacy <code >Controller</code > base class this
112- is true. If using <code >AbstractController</code > instead, which is currently recommended practice, ensure
113- you subscribe to the <code >DataTableFactory</code > service yourself. Alternatively you can bypass the convenience
114- trait and inject the service via regular constructor injection.
108+ Previous versions of this bundle offered a <code >DataTablesTrait</code > which assumed that the
109+ <code >DataTableFactory</code > class was available in the controller's <code >$container</code >. As this
110+ is deprecated in current versions of Symfony you should use dependency injection instead.
115111
116112## Frontend code
117113
0 commit comments