Answers.Body: <p>My guess is the array is empty because there is no content.<br>
  Try <code>$o_matrix_block-&gt;getType()-&gt;getFields();</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-22T11:54:54.643Z
Answers.LastActivityDate: 2015-05-22T11:54:54.643Z
Answers.UserDisplayName: fuling
Answers.Body: <p>my genius colleague found the answer, this will print out the matrix field column names.</p>
  
  <pre><code>$o_user_model = craft()-&gt;userSession-&gt;getUser(); // Get current user
  
  $o_matrix_block_type_model = craft()-&gt;matrix-&gt;getBlockTypeById(5);
  
  $a_fields = $o_matrix_block_type_model-&gt;getFieldLayout()-&gt;getFields();
  
  foreach($a_fields as $o_field_layout_field_model) {
  
      $o_field = $o_field_layout_field_model-&gt;getField();
      var_dump($o_field-&gt;handle);  
  }
  
  die;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-22T12:44:54.260Z
Answers.LastActivityDate: 2015-05-22T12:44:54.260Z
Answers.UserDisplayName: Gary Constable
Body: <p>From a craft matrix block how do i get the field names when no data has yet been entered?</p>
  
  <p>i can write:</p>
  
  <pre><code>$o_matrix_block-&gt;getContent()-&gt;getAttributeConfigs();
  </code></pre>
  
  <p>this will give me an array:</p>
  
  <pre><code> Array
                      (
                          [id] =&gt; Array
                              (
                                  [maxLength] =&gt; 11
                                  [min] =&gt; -2147483648
                                  [max] =&gt; 2147483647
                                  [decimals] =&gt; 0
                                  [type] =&gt; number
                                  [unsigned] =&gt; 
                                  [length] =&gt; 10
                                  [column] =&gt; integer
                              )
  
                          [elementId] =&gt; Array
                              (
                                  [maxLength] =&gt; 11
                                  [min] =&gt; -2147483648
                                  [max] =&gt; 2147483647
                                  [decimals] =&gt; 0
                                  [type] =&gt; number
                                  [unsigned] =&gt; 
                                  [length] =&gt; 10
                                  [column] =&gt; integer
                              )
  
                          [locale] =&gt; Array
                              (
                                  [column] =&gt; locale
                                  [default] =&gt; en_gb
                                  [type] =&gt; locale
                              )
  
                          [title] =&gt; Array
                              (
                                  [required] =&gt; 
                                  [maxLength] =&gt; 255
                                  [label] =&gt; Title
                                  [type] =&gt; string
                              )
  </code></pre>
  
  <p>but I only get the array, when I have entered data.</p>
  
  <p>with out getcontent() but the array elements are wrong</p>
  
  <p>Pls help!</p>
  
  <p>:)</p>
  
Tags: <matrix>
Title: With Matrix blocks how can i get the column names
ThreadText: # With Matrix blocks how can i get the column names
  
  (Asked by: username_0 on 2015-05-22)
  
  From a craft matrix block how do i get the field names when no data has yet been entered?
  
  i can write:
  
  ```
  $o_matrix_block->getContent()->getAttributeConfigs();
  
  ```
  
  this will give me an array:
  
  ```
   Array
                      (
                          [id] => Array
                              (
                                  [maxLength] => 11
                                  [min] => -2147483648
                                  [max] => 2147483647
                                  [decimals] => 0
                                  [type] => number
                                  [unsigned] => 
                                  [length] => 10
                                  [column] => integer
                              )
  
                          [elementId] => Array
                              (
                                  [maxLength] => 11
                                  [min] => -2147483648
                                  [max] => 2147483647
                                  [decimals] => 0
                                  [type] => number
                                  [unsigned] => 
                                  [length] => 10
                                  [column] => integer
                              )
  
                          [locale] => Array
                              (
                                  [column] => locale
                                  [default] => en_gb
                                  [type] => locale
                              )
  
                          [title] => Array
                              (
                                  [required] => 
                                  [maxLength] => 255
                                  [label] => Title
                                  [type] => string
                              )
  
  ```
  
  but I only get the array, when I have entered data.
  
  with out getcontent() but the array elements are wrong
  
  Pls help!
  
  :)
  
  **Tags:** matrix
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-05-22. Score: 1
  
  My guess is the array is empty because there is no content.  
  Try `$o_matrix_block->getType()->getFields();`
  
  
  ---
  
  ### Answer by username_0 on 2015-05-22. Score: 1
  
  my genius colleague found the answer, this will print out the matrix field column names.
  
  ```
  $o_user_model = craft()->userSession->getUser(); // Get current user
  
  $o_matrix_block_type_model = craft()->matrix->getBlockTypeById(5);
  
  $a_fields = $o_matrix_block_type_model->getFieldLayout()->getFields();
  
  foreach($a_fields as $o_field_layout_field_model) {
  
      $o_field = $o_field_layout_field_model->getField();
      var_dump($o_field->handle);  
  }
  
  die;
  
  ```
  
  
  ---
  
  