我正在开发一个简单的CRM系统。
我有前四个步骤。
对于5号,我想有很多方法。可能通过传递变量?
我想从客户视图添加新地址,而不是第二次选择客户。在Addresses / add.ctp上,我不需要显示客户名称或ID,只是以某种方式最终作为外键。
答案 0 :(得分:0)
将Customer ID添加为CustomerAddresses / Add函数的参数。
在您的客户视图中,您将添加$this->Html->link(__('New Address'), array('controller' => 'CustomerAddresses', 'action' => add, $this->data['Customer']['id'] ));
链接,并将$this->data
与您的客户对象一起添加到视图中。
在CustomerAddressesController中:
public function add( $customer_id = null ) {
if( !$this->CustomerAddress->Customer->exists($customer_id)
&& empty($this->request->data['CustomerAddress']['customer_id']) ) {
// Redirect because customer_id does not exist, to avoid SOME security problems
$this->redirect($this->referer());
}
if( $this->request->is('post') ) {
// Whatever you need for your add function. Customer id will already be in $this->request->data
}
$this->set('customer_id', $customer_id);
}
表单中的CustomerAddresses / add.ctp添加<input type="hidden" value="<?=$customer_id?>" />