str_replace() JSON output?
str_replace() JSON output?
Restful Web Services
Posts: 202Questions: 49Answers: 2
Is there anyway to add the str_replace function to a JSON output whilst working with the Editor PHP server script? I need to substitute certain values from my 'checkcode' column and thought I could use some kind of str_replace function but I cannot seem to make it work?
// DataTables PHP library
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;
Editor::inst( $db, 'cms_module_tps_userlisting', 'list_id' )
->fields(
Field::inst( 'listphone' ),
Field::inst( 'create_date' ),
Field::inst( 'checkcode' ),
Field::inst( 'user_id' )
)
->where( 'user_id', $_GET['user_id'] )
->where( 'checkcode', $_GET['checkcode'] )
->process( $_POST )
->json();
Many thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Sure, use a
getFormatter
. Something like:Allan
Thanks Allan, that worked really well.
As you seem to be very adept at using datatables I don't suppose you can point me in the right direction of where I can find documentation illustrating how to add a class to my rows matching that of the value found in
If my checkcode value is 'error' I can create a CSS class .error which will enable me to give the row a red background color, or something like that.
Is that possible?
Thanks
Chris
I have added a class directly in my str_replace, is this a good thing to do though or is there a better way?
Use
columns.createdCell
, or possiblyrowCallback
.That looks fine to me, as long as your Editor can those values.
Allan
Thanks, seems to work well. However, I have another str_replace issue. This doesn't seem to work and I thought it would?
I don't want to display any dates which are 'null', i.e. 0000-00-00 00:00:00, so I replace them with a - symbol. That works fine.
I also want to change the date format which works fine.
However, if I combine the two ->getFormatter functions, the str_replace function doesn't run.
You can't have two different formatter functions - you would need to combine the two operations into a single one.
The code for the
date_sql_to_format()
method is available here.Allan
HI Allan,
Thanks for your continued support. I managed to get a working solution using the following if else statement within the getFormatter function.
Chris