【发布时间】:2014-01-16 00:31:17
【问题描述】:
过滤一些数据后,我创建了一个变量$customers。这个变量是一个简单的数组 具有以下值:
array(
(int) 1 => 'Customer1',
(int) 2 => 'Customer2',
(int) 3 => 'Customer3'
)
我把这个数组从控制器传递给了这样的视图
$this->set('customers', $customers);
在视图中,我在表单中使用此数组,以便用户可以选择一个
echo $this->Form->input('customer_id', array('options' => array($customers)));
选择表单中显示的数据是这个'Customer1', 'Customer2', 'Customer3'
到目前为止,Eveyting 工作正常。
现在,在用户提交数据后,我想在控制器中做一些进一步的逻辑。我想获取用户选择的数据并将其保存在第二个表中。所以我这样做:
$this->Invoice->set('secondtabel', $this->request->data['Invoice']['customer_id']);
数据保存在第二个表中,但问题是保存值 '1', '2', '3' 而不是客户的姓名。如何保存客户的姓名而不是数组中的标识符号。
请多多包涵,我是 cakephp 和一般 php 的新手。
【问题讨论】:
标签: php cakephp cakephp-2.0 cakephp-model