Answers.Body: <p>You have to loop the Matrix field first, something like this:</p>
  
  <pre><code>foreach($entry-&gt;matrixHandle-&gt;all() as $block) {
     echo $block-&gt;fieldHandle;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-04T12:41:34.060Z
Answers.Text: thanks @gioppe  i should have used one() or all() because it returns craft\elements\db\MatrixBlockQuery and i had to get result first
Answers.UserDisplayName: user9975
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-04T08:20:51.483Z
Answers.LastActivityDate: 2020-02-04T08:20:51.483Z
Answers.UserDisplayName: gioppe
Body: <p>I am trying to process a text field inside a Matrix field.</p>
  
  <p>In the controller I have this to get posted params:</p>
  
  <pre><code>$element-&gt;setFieldValuesFromRequest($fieldsLocation);
  </code></pre>
  
  <p>If I want to process a custom text field, I can do it easily with</p>
  
  <pre><code>$result=$element-&gt;getFieldValue('textFieldHandle')
  </code></pre>
  
  <p>which <code>$result</code> is exactly the text field value.</p>
  
  <p>but if I have this text field in Matrix field, if I do this:</p>
  
  <pre><code>$result=$element-&gt;getFieldValue('matrixFieldHandle')
  craft::dd($result)
  </code></pre>
  
  <p>I get a <code>craft\elements\db\MatrixBlockQuery</code> object which I don't know how I can fetch text value from this object. </p>
  
Tags: <craft3><matrix>
Title: How to process Matrix field in controller
ThreadText: # How to process Matrix field in controller
  
  (Asked by: username_0 on 2020-02-03)
  
  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.
  
  **Tags:** craft3, matrix
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-04. Score: 2 | Accepted answer
  
  You have to loop the Matrix field first, something like this:
  
  ```
  foreach($entry->matrixHandle->all() as $block) {
     echo $block->fieldHandle;
  }
  
  ```
  
  > **Comments:**
  > **username_0**: thanks @username_1  i should have used one() or all() because it returns craft\elements\db\MatrixBlockQuery and i had to get result first  
  
  ---
  
  