cakephp,表单的选择是通过查询生成的
我在控制器中有此查询,
$clientslist = $this->Client->query("SELECT client_name FROM clients WHERE active=1");
如何通过表单中的选择来显示我的客户列表?
echo $this->Form->input('clientname', array('type' => 'select', 'options' => ??????));
谢谢
编辑
问题
我已经解决了控制器中的
$clientslist = $this->Client->find('list', array('fields' => array('Client.client_name'), 'conditions' => array('Client.active' => '1')));
$this->set('clientslist', $clientslist);
,
echo $this->Form->input('cliente', array('type' => 'select', 'options' => $clientslist));
我现在有另一个问题,
视图选择框的每个选项的值是id 我如何在值中使用客户的名称?
I have this query in the controller
$clientslist = $this->Client->query("SELECT client_name FROM clients WHERE active=1");
how can i show my clients list with a select in a form?
echo $this->Form->input('clientname', array('type' => 'select', 'options' => ??????));
thanks
EDIT
i've solved my problem
in controller
$clientslist = $this->Client->find('list', array('fields' => array('Client.client_name'), 'conditions' => array('Client.active' => '1')));
$this->set('clientslist', $clientslist);
in view
echo $this->Form->input('cliente', array('type' => 'select', 'options' => $clientslist));
i have another problem now
in view the value of every option of the selectbox is the id
how can i use the name of the client in the value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的查询更改为以下内容:
这将自动构建一个
ID, NAME
选项列表以在选择框中使用。Change you query to the following:
This will automatically build an option list of
ID, NAME
for use in the select box.