从控制器发送多个变量到视图时出错。 视图中产生错误
Message: Undefined variable: heading
控制器代码:
public function index()
{
$this->load->model('database');
$result['a'] = $this->database->factory_view();
$this->load->view('header');
$heading['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
$this->load->view('factory',$result,$heading);
$this->load->view('footer');
}
答案 0 :(得分:1)
$data['posts'] = $posts;
$data['comments'] = $comments;
$this->load->view('your_view', $data);
在taemplate中查看...
foreach($posts as $post) {
...
}
foreach($comments as $comm) {
...
}
答案 1 :(得分:1)
public function index()
{
$this->load->model('database');
$result['a'] = $this->database->factory_view();
$this->load->view('header');
$result['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
$this->load->view('factory',$result);
$this->load->view('footer');
}
答案 2 :(得分:0)
就这样
public function index()
{
$this->load->model('database');
$result['a'] = $this->database->factory_view();
$this->load->view('header');
$result['heading']= '<span class="float-left" style="margin-top:10px;">
<h3>Machinery and Factory</h3></span>';
$result['param_1'] = "xyz";
$result['param_2'] = "abc";
$this->load->view('factory',$result);
$this->load->view('footer');
}
答案 3 :(得分:0)
尝试一下。这将起作用...
public function index()
{
$this->load->model('database');
$data['a'] = $this->database->factory_view();
$this->load->view('header');
$data['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
$this->load->view('factory',$data);
$this->load->view('footer');
}
然后在您的页面视图内调用$a
和$heading
。