cakephp-datatables icon indicating copy to clipboard operation
cakephp-datatables copied to clipboard

Call to undefined method DataTables\Controller\Component\DataTablesComponent::callback()

Open jsonjuri opened this issue 5 years ago • 2 comments

Hi,

I am loading $columns from the controllers and pass them to the view with set.

After setting the render attribute in the columns array like in your documentation CakePHP was giving the following error:

Call to undefined method DataTables\Controller\Component\DataTablesComponent::callback()

I found out callback was only in DataTablesHelper not in the Component. I copied this function to DataTablesComponent:

public function callback(string $name, array $args = []) : CallbackFunction
{
        return new CallbackFunction($name, $args);
}

And added use to the top of DataTablesComponent

use DataTables\Lib\CallbackFunction;

Now it's working fine, but not sure it was meant to work like this? Or did you add it to Helper with the purpose of loading $columns in the view?

jsonjuri avatar May 12 '19 16:05 jsonjuri

The columns are shared between controller and view, but the callbacks are a pure view matter.

I suggest you use ColumnDefinitions interface and add the callback in the view. Like $columns['name']['callback'] = ….

ypnos-web avatar May 12 '19 18:05 ypnos-web

You are right, thats working fine. Thanks!

jsonjuri avatar May 13 '19 16:05 jsonjuri