Search code examples
phppimcore

Replace row name by variable


In this code :

$structuredData->setRow_1__column_1($var1);

is there a way to replace Row_1 by a variable $row ?

https://pimcore.com/docs/pimcore/current/Development_Documentation/Objects/Object_Classes/Data_Types/Structured_Table.html


Solution

  • PHP supports variable functions, meaning you can use a variable that contains a sting + parentheses to call a function with that name. Here's how that works in your case:

    $row = 'Row_6';
    
    $setRow = "set{$row}__column_1"; 
    
    $structuredData->$setRow($var1);