我在 CakePHP 中有一个表单,如下 addticket.ctp
<html>
<?php
echo $this->Form->create('Ticket', array('url' => array('controller' => 'tickets', 'action' =>'addtickets'),
'enctype' => 'multipart/form-data'));
echo $this->Form->input('title',array('label'=>'Title'));
echo $this->Form->input('attachment', array('between'=>'<br />','type'=>'file',
'label'=>'Attachment'));
echo $this->Form->input('stepstoreproduce',array('label'=>'Steps To Reproduce'));
echo $this->Form->input('category',array(
'label'=>'Category',
'options'=>array(
'IT Support',
'IT HelpDesk'
)));
echo $this->Form->input('priority',array(
'label'=>'Priority',
'options'=>array(
'Low',
'Medium',
'High'
)));
echo $this->Form->input('Comment.comment',array(
'type'=>'textarea',
'label'=>'Comments'
));
echo $form->input('public',array('type'=>'radio',
'options' => array(
'1'=>'Yes',
'0'=>'No',
),
'default'=>'0'));
echo $form->input('created_by',array('value'=>$_SESSION['Auth']['User']['id'],'type'=>'hidden'));
echo $this->Form->end('Submit Ticket');
?>
</html>
我有带有以下代码的模型ticket.php
var $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'ticket_id'
)
);
我有带有 addticket() 函数的tickets_controller,如下所示
if ($this->Ticket->saveAll($this->data)){
$this->Session->setFlash('Ticket created');
}
else {
$this->Session->setFlash('Cannot create a ticket');
}
问题 问题是我的数据库中有两个表:1.tickets 2.Comments(ticket_id 是外键)
我想将门票数据插入tickets
表格并将评论数据插入comments
表格。据我所知,将名称更改为Comment.comment
将在评论表中插入数据。
但我想在评论表和
门票和评论中添加userid
和。ticket_id
created_by
请帮助提前谢谢