We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to send an array as a parameter while using link_to for calling an controller/action in volt

<ul class="pager">
    <li class="pull-middle">
        {% set arr= {'one', 'two', 'three'} %}
        {{ link_to("employee/export/"~arr[], '<i class="icon-download-alt"></i> Export to excel', "class": "btn btn-default") }} 
    </li>
</ul>
edited Dec '16
{{ link_to('employee/export/'~['my','array','values']|join('/')) }}

I just came to know another method....just serialize the data before sending and unserialize the data after receiving it in the controller.

edited Dec '16

One more important consideration is the URI character length. Afaik, the defacto limit is 2048 characters, so if your serialized URI is longer than that, some browsers may throw a fit. There's detailed info about this here: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers#answer-417184

edited Dec '16

so how can i send array which i set it in the controller ...can you explain me clearly about the attributes in your solution... {{ link_to('employee/export/'~['my','array','values']|join('/')) }}

edited Dec '16

My example won't solve the length problem, but here's the break-down:

link_to("employee/export/") i suppose you know that this generates a link the EmployeeController::exportAction

link_to("employee/export/"~ the tilde character concatenates strings in volt templates

link_to("employee/export/"~["my","array","values"]|join("/")) the last bit is an arbitrary array followed by a volt filter called join, which concatenates the array values and glues them with the / character