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 create a drop down box in a table block using volt

i am a beginner in phalcon, How to create a drop down box in a table block and the values in drop down box should be fetched from db...this should be done using volt....can anyone help? below is my code....


<table class="table table-bordered table-striped" align="center">
    <thead>
        <tr>
            <th>Id</th>
            <th>ROLE NAME</th>
            <th>ASSIGNEE</th>            
        </tr>
    </thead>
    <tbody>
    {% endif %}
        <tr>
            <td>{{user.id }}</td>
            <td>{{ user.name }}</td>
            <td>{{*DROPDOWN LIST*}}</td>            

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

the 3rd colum should show the drop down list



85.5k

by being complatly blind i can help you that much, i think the rest you have to dig for yourself

if you use bootstrap .... otherwise you have to dig the css for yourself


class Assigned extends \Phalcon\Mvc\Model { //fix class name
    public function initialize()
    {
        $this->setSource("assing"); //set your table name
    }
}

in your controller


public function indexAction(){

    $assigned_records = Assigned::find([
        "conditions" => "user_id = ?1 AND deleted = ?2"
        "bind" [
            1 => $USER_ID //fix this
            2 => 0 //not delted if you even have such a flag if not remove it i dont know your table structure
        ]
    ]);

    $this->view->setVar("assigned", $assigned_records);
}

in your view // https://getbootstrap.com/components/#dropdowns


<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

    {% for assign in assigned %}
      <li>
        <a href="#">
        {{ assign.name }} //assign is an isntance of phalcon/mvc/model now, so when you have access to your db properties
        </a>
      </li>
      {% endfor %}
  </ul>
</div>