【发布时间】:2017-05-14 07:36:04
【问题描述】:
当用户登录我的站点时,他们将被定向到控制器内的函数 confirmTicket(名为 ticketController)。这需要一个名为 data 的数组,该数组在名为 addTicket 的函数内创建。但是,这些数据随后会在带有表单的视图中使用。此表单应该能够确认用户对存储在数据库中的内容感到满意,并将此表单发送到ticketController/confirmTicket。其中的第一个命令是获取数组,因此程序在这些页面之间循环而不会去任何地方。代码如下:
用户登陆这里,在confirmTicket 函数内:
public function confirmTicket() {
$data = $this->addTicketIndex();
//code to load confirmAdd view never gets executed due to above command, but can't come before as $data is required
}
这意味着 addTicketIndex() 已运行:
function addTicketIndex() {
$this->load->helper('form');
$this->load->view('addTickets');
}
这会加载 addTickets 视图:
<!DOCTYPE html>
<head>
<title> Submit a new issue </title>
</head>
<body>
<div class="banner">
<?php echo "Welcome back, ". $this->session->userdata('forename'); ?>
</div>
<?php
echo form_open("TicketController/addTicket");
?>
<div id="container">
<label for="summary"> Please enter the issue you are experiencing, be as specific as possible (assets numbers of PC's etc.) but please refrain from entering any personal information such as passwords. </label>
<br>
<input type="text" name="issue" placeholder="Enter your issue here">
<br>
</div>
</body>
</head>
这将打开addTicket() 函数:
public function addTicket() {
$this->form_validation->set_rules('issue', 'Summary', 'required|max_length[500]');
if ($this->form_validation->run() == FALSE) {
echo "It appears you have not entered an issue or that your issue is over 500 characters";
$this->load->view('addTickets');
} else {
$temp = $this->input->post('issue');
$data["ticket"] = array (
'priority' => '1',
'summary' => $this->input->post('issue'),
'status' => 'Submitted',
'category' => exec("python C:/xampp/htdocs/ci/assets/machineLearning.py machineLearning $temp 2>&1"),
'itemsRequired' => ' ',
'lastUpdate' => date('Y-m-d G:i:s'),
'ownerID' => $this->session->userdata('username'),
'managerID' => 'tech'
);
$this->load->view("confirmAdd");
}
}
然后加载confirmAdd 视图:
<!DOCTYPE html>
<html>
<head>
<title> Are you sure? </title>
</head>
<body>
<?php
echo "Please help us improve our Machine Learning by selecting the appropriate category from the drop down box below. It is in your interest to select the closest category so your issue can be resolved as soon as possible. <br>";
?>
<?php echo form_open('ticketController/confirmTicket'); ?>
<label for="cngCategory"> Category </label><br>
<select name="newCategory">
<option value="idCard">ID Card</option>
<option value="printer">Printer</option>
<option value="byod">BYOD (Bring Your Own Device) </option>
<option value="email">Email</option>
<option value="desktop_pc">Desktop</option>
<option value="forgotten_password">Forgotten Password </option>
<option value="lost_work">Lost Work </option>
</select>
<input type="submit" value="Confirm">
</body>
</html>
然后将我定向到confirmTicket 函数,我希望在该函数中使用$data 调用数据库并插入票证,但是由于第一行是$data = $this->addTicketIndex();,因此循环重新开始.有没有办法只执行一次这些步骤然后停止以便继续处理?
【问题讨论】:
-
@wolfgang1983 据我所知,尝试过这在我的情况下不起作用。我从
addTicket内部加载视图和数据,是的,它工作正常,但是我需要再次confirmTicket内部的数据。这样做的方法是通过$data = $this->addTicketIndex();行,对吗?哪个会重新开始重定向?还是我错过了什么? -
@wolfgang1983 同样,通过从确认视图调用
addTicket函数,意味着再次设置$data,然后再次加载视图 - 另一个循环?
标签: php codeigniter model-view-controller codeigniter-3 php-7