这是我的控制器托管后给出错误解析错误:语法错误,意外' ['在第18行的/home/a8012112/public_html/application/controllers/User.php
public function index()
{
$result = $this->Usermodel->index();
$this->load->view('user/header');
$this->load->view('user/index', ['result' => $result]);
$this->load->view('user/footer');
}
答案 0 :(得分:1)
public function index()
{
$data['result'] = $this->Usermodel->index();
$this->load->view('user/header');
$this->load->view('user/index', $data);
$this->load->view('user/footer');
}
然后在视图中,您应该使用$result
来获得结果:
<p>
<?php echo $result; ?>
</p>
有关更多信息和示例,请查看CodeIgniter文档:https://codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view