【发布时间】:2018-06-06 20:16:30
【问题描述】:
我真的不知道如何在 CodeIgniter 项目中组织我的代码。在一个视图中,我有一个表单允许在提交后获得信息。但信息显示在同一视图上。信息以多种方式显示(例如使用 PHP 或控制器部分中的 Ajax 和 JSON 编码)。
我的看法:
<form action="#" method="post">
<p>Your name : <input type="text" name="name" /></p>
<p><input type="submit" value="OK"></p>
</form>
我可以在视图中使用它来验证用户是否按下了按钮提交?
if (isset($_POST['submit'])) {// the code I want to to show after submit}
点击提交按钮后我想显示的内容:
<select class="mylist">
<?php foreach($groups as $each){ ?>
<option value="<?php echo $each->groupname; ?>"><?php echo $each->groupname; ?></option>';
<?php } ?>
</select>
<table id="table" class="display" style="width:80%">
<thead>
<tr>
<th>Name</th>
<th>SurName</th>
<th>ID</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>SurName</th>
<th>ID</th>
</tr>
</tfoot>
</table>
控制器:
public function index()
{
$this->load->view("myview.php");
}
public function getlist()
{
$this->load->model('mymodel');
// Method to get the values of the list in the database
}
public function get_test_datatables()
{
// Method to fill the datatable part
echo json_encode($output);
}
JS Functions :
$(document).ready( function () {
$('#table').DataTable({
//Get the data with ajax
})
)}
在我按下提交按钮后,我还想检查一个复选框是否被选中(如果它在数据库中等于true,我必须选中该框,如果它等于false,我不必检查)。我要不要在视图中做类似的事情:
if(checkbox->value == true)
{
<input type="checkbox" name="vehicle" value="Bike" checked> I have a bike<br>
}
else {
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
}
谢谢
【问题讨论】:
-
显示完整的 ajax 函数和所有代码。有一个你可能想要为 CI 研究的插件,称为 ignited datatables,它可能会帮助你。否则,数据表文档非常适合这类事情。多尝试/充实一下,然后回来。就目前而言,我相信您要求我们为您做太多事情。
标签: javascript php codeigniter templates