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

Render table values in volt

how can i get all cell values from table in volt view

below is my code

{% for table in page.items %} {% if loop.first %} <table class="table table-bordered table-striped" align="center" border=2 id="data"> <thead> <tr> <th>Id</th> <th> NAME</th> <th>role</th>
</tr> </thead> <tbody> {% endif %} <tr> <td>{{ table.id }}</td> <td>{{ table.name }}</td> <td> {% for element in role %} {{ element }}
{% endfor %} </td> <td width="7%">{{ radio_field("access", "value": "grant") }} Grant </td> <td width="7%">{{ radio_field("access", "value": "deny") }} Deny </td>

    </tr>
{% if loop.last %}
</tbody>    

</table> {% endif %} {% else %} No products are recorded {% endfor %}

......how can i get these cell values to controller from the view

edited Oct '16

First of all, post your code properly formatted so we can understand it more quickly.

{% for table in page.items %}
    {% if loop.first %}
        <table class="table table-bordered table-striped" align="center" border=2 id="data">
            <thead>
                <tr>
                    <th>Id</th>
                    <th> NAME</th>
                    <th>role</th>
                </tr>
            </thead>
        <tbody>
    {% endif %}
    <tr>
        <td>{{ table.id }}</td>
        <td>{{ table.name }}</td>
        <td>{% for element in role %} {{ element }} {% endfor %}</td>
        <td width="7%">{{ radio_field("access", "value": "grant") }} Grant</td>
        <td width="7%">{{ radio_field("access", "value": "deny") }} Deny </td>
    </tr>
{% if loop.last %}
</tbody>
</table>
{% endfor %}

{# its invalid syntax from here, have you copied the code correctly? #}
{% else %}
No products are recorded
{% endfor %}

Second, what is the actual problem with the code? Only saying it doesnt work wont help us figure it out. Does it die with an error message? Or is the response different from what you expect? Do you set the view->page items from your controller?

edited Oct '16

the code is not giving any errors....i want to know how can post the values in table to the controller from the view......like we do $this->view->data=$data......how can we do in the other way

First of all, post your code properly formatted so we can understand it more quickly.

{% for table in page.items %}
  {% if loop.first %}
      <table class="table table-bordered table-striped" align="center" border=2 id="data">
          <thead>
              <tr>
                  <th>Id</th>
                  <th> NAME</th>
                  <th>role</th>
              </tr>
          </thead>
      <tbody>
  {% endif %}
  <tr>
      <td>{{ table.id }}</td>
      <td>{{ table.name }}</td>
      <td>{% for element in role %} {{ element }} {% endfor %}</td>
      <td width="7%">{{ radio_field("access", "value": "grant") }} Grant</td>
      <td width="7%">{{ radio_field("access", "value": "deny") }} Deny </td>
   </tr>
{% if loop.last %}
</tbody>
</table>
{% endfor %}

{# its invalid syntax from here, have you copied the code correctly? #}
{% else %}
No products are recorded
{% endfor %}

Second, what is the actual problem with the code? Only saying it doesnt work wont help us figure it out. Does it die with an error message? Or is the response different from what you expect? Do you set the view->page items from your controller?

Wait, you want to save the user input? That's what forms and post requests are for...

Currently you have one input (two radios) in each row. Now, if you check the generated HTML you will see that every row has the same input name (access). You will have to name them differently in each row. Wrap the table in a form tag, then you can process it in your controller:

class MyController
{
    public function myAction()
    {
        if($this-request->hasPost('access')) {
            // do your stuff
        }
    }
}


43.9k

Hi,

to complete the good responses given above, don't forget to declare the form tag:


{{ form('table/save', 'method': 'post') }}

    {{ submit_button('Send') }}
    {% for table in page.items %}
        {% if loop.first %}
            <table class="table table-bordered table-striped" align="center" border=2 id="data">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th> NAME</th>
                        <th>role</th>
                    </tr>
                </thead>
            <tbody>
        {% endif %}
        <tr>
            <td>{{ table.id }}</td>
            <td>{{ table.name }}</td>
            <td>{% for element in role %} {{ element }} {% endfor %}</td>
            <td width="7%">{{ radio_field("access", "value": "grant") }} Grant</td>
            <td width="7%">{{ radio_field("access", "value": "deny") }} Deny </td>
        </tr>
    {% if loop.last %}
    </tbody>
    </table>
    {% endfor %}

    {# its invalid syntax from here, have you copied the code correctly? #}
    {% else %}
    No products are recorded
    {% endfor %}

{{ end_form() }}
edited Oct '16

the third element in table is a drop down box(with name role) if i try to send that value to the other controller......print_r($this->request->getPost()); am just getting dropdown value of the last cell in the table....but i want to get all the values of the select tab



77.7k
Accepted
answer
edited Oct '16

the third element in table is a drop down box(with name role) if i try to send that value to the other controller......print_r($this->request->getPost()); am just getting dropdown value of the last cell in the table....but i want to get all the values of the select tab

Check the generated HTML! You will see that every dropdown has the name access, so any latter overwrites the former.

You'll have to index the dropdowns:

{{ select("access-"~loop.index) }}