FriendsOfCake/cakephp-csvview

Layout and helpers?

Closed this issue · 8 comments

It would be especially nice to be able to use this plugin with some of my formatting helpers at my disposal.

Isnt that possible using callables/closures?

@holisticnetworking how would you imagine that working?

One way might be to specify a "formatter" callable for each field. Thus $_extract might look like such:

$_extract = [ ['price'] => 'NumberHelper::currency' [, 'col', 'col'] ]

Is this something you would be interested in building? I'm not sure how the user interface would be, and as the current formatting methods work fine for me, I'm not really inclined to write it.

We can help you with tests once the pr is up.

Let me look into the code a bit before I say something silly...

I'm looking at the code, and while there is a variable created called "formatter," really, that's just an extraction function. It does not actually format anything in the sense of NumberHelper or similar functions. I'm going to play around with this some and see what I can do.

Something like this could indeed work:

$_formatters = [
    'price' => ['NumberHelper::currency' [, 'col', 'col']],
    'some_field' => function ($value) { //format }
    ....
]

And then apply those callable if available prior to finally formatting the output?

ADmad commented

You are use callables in $_extract array to achieve whatever formatting you want for a field. The README has example for it.