Editor - PHP Backend - set getValue from another column

Editor - PHP Backend - set getValue from another column

hapihapi Posts: 17Questions: 3Answers: 0

Hi, I am using php backend for Editor. I have a table with a CLOB. CLOBs are not supported. Hence I am trying to read and write the CLOB separately.

My table columns:
ID, TEXT, TEXT_CLOB

In Fileds I have defined only the ID and TEXT.

All works fine.

Can I now use for Field TEXT a formatter and read from TEXT_CLOB with my own DB query? My problem is, that the getFormatter dos not know which row is processed. I would need the ID, then I can read from TEXT_CLOB and return that value.

Same I would need for setValue.

In alternative I was trying to do this in ->on('postGet', but as far as I can see, I cannot modify here the data wich will be returned to the client. Same for ->on('beforeUpdate' etc., Can I modify the data before it is used to update the DB?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 1,858Questions: 55Answers: 280
    Answer ✓

    The sky is the limit! PostGet is great to manipulate data. Just pass it by reference.

    https://datatables.net/forums/discussion/61108/how-to-construct-orthogonal-start-date-data-structure

  • hapihapi Posts: 17Questions: 3Answers: 0

    Hi, many thanks for the hint. by reference was the key.

    However not an easy task (for me). My problem was, that on pre/post Create/Edit, the data is not yet commit by editor. To realize this, took me some time. I can't update the row if INSERT is not commit and I can't update if another UPDATE is not commit.

    However finally I managed to do it.
    * on preCreate/Edit I change the data to fit TEXT column, I remember the long TEXT
    * on postCreate/Edit I remember the ID (primary key) in a global variable
    * once editor's process is completed (after ->json();) I check if there is something in the ID and I update TEXT_CLOB for the given ID with my own db connection.

    Indeed, the limit is the sky. o:)

  • hapihapi Posts: 17Questions: 3Answers: 0

    Just one more finding on CLOB reading. In such cases the $val is a resource (stream), and the ->load() function will load it as a string. The load() function comes from the oracle library providing the database connection.

            Field::inst( 'CLOB_COLUMN' )
                ->getFormatter( function ( $val ) {
                    return $val->load();
                } ),
    

    It could be that easy... :smiley:

Sign In or Register to comment.