我需要有关codeigniter中视图的帮助。通常我只是以同样的方式行事,这是工作。现在我感到困惑,或者我错了。
这是控制器:
...
$curl_exec = curl_exec($ch);
$result = json_decode($curl_exec, TRUE);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpcode == 200)
{
$msg['success'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
} elseif ($httpcode == 500) {
$msg['double'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
} {
$msg['others'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
}
这就是观点:
<?php
if (isset($success)) {
echo "<div class='alert alert-danger alert-dismissible'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>";
echo "<h4><i class='icon fa fa-ban'></i> Alert!</h4>";
echo "$success";
echo "</div>" ;
}
?>
<?php
if (isset($double)) {
echo "<div class='alert alert-danger alert-dismissible'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>";
echo "<h4><i class='icon fa fa-ban'></i> Alert!</h4>";
echo "$double";
echo "</div>" ;
}
?>
<?php
if (isset($others)) {
echo "<div class='alert alert-danger alert-dismissible'>";
echo "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>";
echo "<h4><i class='icon fa fa-ban'></i> Alert!</h4>";
echo "$others";
echo "</div>" ;
}
?>
// Form
<div class="form-group">
<label for="exampleInputEmail1">Product Code</label>
<input type="text" name="codeproduct" id="codeproduct" class="form-control" placeholder="Product Code">
</div>
// ...
// End Form
该消息应显示在警告框中,但不会显示。如果我在条件消息显示结束时添加exit();
。我的代码有什么问题吗?
答案 0 :(得分:0)
你需要把&#39;否则&#39;在最后一个名言上。
if($httpcode == 200)
{
$msg['success'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
} elseif ($httpcode == 500) {
$msg['double'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
} else {
$msg['others'] = 'Succcessfully completed step 1!';
$this->load->view('back/vproductadd', $msg);
}
答案 1 :(得分:0)
问题是 - 如果你让控制器中的脚本死掉,CI还没有完成。 因为它会加载@first所有视图,以便最终将它们放出来。
下面的应用程序流程图应该显示它是如何工作的。 Sed Global substitution