0
我有兩個控制器合作伙伴和交易。形式CakePhp 1形成多個表
當我添加交易有一個現場合作夥伴ID,並在cakephp這將生成與所有合作伙伴的下拉菜單。如果用戶想要添加新的合作伙伴,他們可以點擊複選框並添加表單。試圖添加合作伙伴輸入框,並且這會創建新的合作伙伴,但它在交易表中會將所選合作伙伴的合作伙伴ID從下拉菜單中放下,而不是新合作伙伴。
新政教職員
<div class="deals form">
<h2>Add New Deal</h2>
<p>Use the form below to fill in the new deals details.</p>
<?php echo $form->create('Deal');?>
<?php
echo $cksource->create();
echo $form->input('title');
echo $form->input('price');
echo $form->input('market_price');
echo $form->input('discount');
echo $form->input('buy_link');
echo $form->input('image');
$config['toolbar'] = array(
array('Source', '-', 'Bold', 'Italic', 'Underline', 'Strike', '-','BulletedList'),
array('Image', 'Link', 'Unlink', 'Anchor')
);
?><label>Deal Highlights</label><?php
echo $cksource->ckeditor('highlights', array('config'=>$config));
?><label>Deal Fine Print</label><?php
echo $cksource->ckeditor('fine_print', array('config'=>$config));
echo $form->input('description');
?><hr />
<h3>Partners Details<?php
echo $form->input('partner_id');
echo $form->input('Partner.name');
echo $form->input('Partner.address1');
echo $form->input('Partner.city');
echo $form->input('Partner.county');
echo $form->input('Partner.postcode');
echo $form->input('city_id');
?><hr />
<h3>Schedule Deal<?php
echo $form->input('start');
echo $form->input('end');
echo $cksource->end();
?>
<?php echo $form->end(__('Submit', true));?>
</div>
新政控制器
function admin_add() {
if (!empty($this->data['Partner']['name'])) {
$this->data['Deal']['partner_id'] = "";
if ($this->Deal->Partner->saveAll($this->data)) {
$this->Session->setFlash(__('The deal has been saved', true));
$this->redirect(array('controller'=>'deals', 'action' => 'add'));
} else {
$this->Session->setFlash(__('The deal could not be saved. Please, try again.', true));
}
} else {
if ($this->Deal->saveAll($this->data)) {
$this->Session->setFlash(__('The deal has been saved', true));
$this->redirect(array('controller'=>'deals', 'action' => 'add'));
}
}
$partners = $this->Deal->Partner->find('list');
$cities = $this->Deal->City->find('list');
$this->set(compact('partners', 'cities'));
}
任何想法的傢伙?如果你知道一個更好的方式來做到這一點會很樂意聽到它,
感謝 戴夫
然後將不會有合作伙伴id鏈接交易和新的合作伙伴。 – Dave
使用$ this-> Deal-> Partner-> saveAll($ this-> data)而不是$ this-> Deal-> saveAll($ this-> data) –
會是$ this-> Deal-> Partner- > create()以及? – Dave