1

I am trying to process a text field inside a Matrix field.

In the controller I have this to get posted params:

$element->setFieldValuesFromRequest($fieldsLocation);

If I want to process a custom text field, I can do it easily with

$result=$element->getFieldValue('textFieldHandle')

which $result is exactly the text field value.

but if I have this text field in Matrix field, if I do this:

$result=$element->getFieldValue('matrixFieldHandle')
craft::dd($result)

I get a craft\elements\db\MatrixBlockQuery object which I don't know how I can fetch text value from this object.

1 Answer 1

2

You have to loop the Matrix field first, something like this:

foreach($entry->matrixHandle->all() as $block) {
   echo $block->fieldHandle;
}
1
  • thanks @gioppe i should have used one() or all() because it returns craft\elements\db\MatrixBlockQuery and i had to get result first
    – user9975
    Commented Feb 4, 2020 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.