我有一个应用程序,用户可以添加他们的查询(ItQueries/add)。当 IT 部门查看查询 (ItQueries/view/1) 时,他们应该能够对其进行评论/响应。到目前为止我所做的是。
在 IT 查询的视图中,我调用了 IT 部门添加响应的元素。下面是我如何调用元素
<?php echo $this->Element('/ItQueryResponses/add'); ?>
在提交 ItQueryResponses 时,我希望该操作重定向到 ItQueris 的查看页面,并在其下方添加评论。
这是我的元素代码
<?php echo $this->Form->create('ItQueryResponse', array('action' => 'add')); ?>
<?php echo __('Add It Query Response'); ?>
<?php
echo $this->Form->input('it_query_id');
echo $this->Form->input('response');
?>
<?php echo $this->Form->end(__('Submit')); ?>
这是我对 ItQueryResponseController 的添加函数
public function add() {
if ($this->request->is('post')) {
$this->ItQueryResponse->create();
if ($this->ItQueryResponse->save($this->request->data)) {
$this->Session->setFlash(__('The it query response has been saved'));
$this->redirect(array('Controller' => 'ItQueryResponses', 'action' => 'view'));
} else {
$this->Session->setFlash(__('The it query response could not be saved. Please, try again.'));
}
}
}
这是我的 ItQueryResponses 视图的代码
<h2><?php echo __('It Query Response'); ?></h2>
<dl>
<dt><?php echo __('Response'); ?></dt>
<dd>
<?php echo h($itQueryResponse['ItQueryResponse']['response']); ?>
</dd>
<dt><?php echo __('Created'); ?></dt>
<dd>
<?php echo h($itQueryResponse['ItQueryResponse']['created']); ?>
</dd>
</dl>
下面是我的 ItQueriesController
<?php
App::uses('AppController', 'Controller');
class ItQueriesController extends AppController {
/** index method
public function index() {
$this->ItQuery->recursive = 0;
$this->set('itQueries', $this->paginate());
}
/** view method
public function view($id = null) {
$this->ItQuery->id = $id;
if (!$this->ItQuery->exists()) {
throw new NotFoundException(__('Invalid it query'));
}
$this->set('itQuery', $this->ItQuery->read(null, $id));
}
/** 添加方法
public function add() {
if ($this->request->is('post')) {
$this->ItQuery->create();
if ($this->ItQuery->save($this->request->data)) {
$this->Session->setFlash(__('The it query has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The it query could not be saved. Please, try again.'));
}
}
$hrEmployees = $this->ItQuery->HrEmployee->find('list');
$this->set(compact('hrEmployees'));
}
/**OTHER CODE*/
}
如果有人可以向我展示我如何重定向到 ItQueryResponses 视图并将 ItQueryResponse 放在视图下方,那就太棒了。