模型/ pages_m.php
function test()
{
$this->load->database();
//$this->db->SELECT('*');
$q = $this->db->get("register");
//if($q->num_rows() > 0)
foreach ($q->result() as $row)
{
return $q->result();
}
return array();
}
控制器/ pages.php
function test()
{
$this->load->model("pages_m");
$data['records'] = $this->pages_m->test();
$this->load->view("test",$data);
}
查看/ test.php的
<?php
<table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php
foreach($records as $row):
?>
<tr>
<td><?=$row->id?></td>
<td><?=$row->name?></td>
<td><?=$row->code?></td>
</tr>
<?php
endforeach;
?>
An Error Was Encountered
无法加载请求的文件:test.php
此错误在屏幕上打印。
链接是localhost/codeigniter/index.php/pages/test
因为我是这个框架工作的新手,所以我找不到解决方案,让我感到困惑
答案 0 :(得分:0)
在您的视图文件中,您只对php代码不敬。而你在视图中所做的,你已经在php标签中编写了html表格代码。
view/test.php
<?php // remove this
<table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
</tr>
<?php
foreach($records as $row): //this is wrong ':', use '{' instead
?>
<tr>
<td><?=$row->id?></td> // write <?php not just <?
<td><?=$row->name?></td> // write <?php not just <?
<td><?=$row->code?></td> // write <?php not just <?
</tr>
<?php //this block doesn't required
endforeach;
?>
如果你仍然希望将你的html代码保存在php中,你必须要回应它。 即
<?php
echo "<html>
<body>
<p>your html content </p>
</body>
</html>";
?>
答案 1 :(得分:0)
为您的模型添加此代码
function test()
{
$this->load->database();
//$this->db->SELECT('*');
$q = $this->db->get("register");
//if($q->num_rows() > 0)
foreach ($q->result() as $row)
{
$data[] = $row['fieldValue'];
}
return $data;
}