1

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!

:)

1

My guess is the array is empty because there is no content.
Try $o_matrix_block->getType()->getFields();

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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