【发布时间】:2018-04-16 11:04:31
【问题描述】:
嘿,我是 cakePHP 新手,我正在学习书签教程,但我使用的是产品表而不是书签表, 这里我想要的是在添加新产品时,我想在输入字段 user_id 中显示 username 而不是 user_id。
<?= $this->Form->create($product) ?>
<fieldset>
<legend><?= __('Add Product') ?></legend>
<?php
echo $this->Form->input('user_id', ['options' => $users]);
echo $this->Form->input('title');
echo $this->Form->input('description');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
UsersTable 有
id,
username,
email,
password
我关注了$username = $this-Users->find('list')
但我真的不明白如何编写这个查询。
我需要运行什么查询?,
【问题讨论】:
-
确保您使用
list方法获得$users。另外,确保用户表的displayField是username -
谢谢@yBrodsky,当然表的diplayField是用户名,我遵循命名约定,现在帮我弄清楚,我需要做什么?
-
向我们展示您的查询以获得
$users -
先生,我还没有写任何查询,我只是烘焙了表格。
-
签入您的控制器。 $users 来自某个地方。看看@FrankSunnyman 的回答
标签: cakephp cakephp-3.0 cakephp-3.x