我目前正在学习 CodeIgniter 并将其用于一个小项目。我想制作一个模板,这样我就不需要为视图编写重复的代码。我喜欢 jruzafa 在这篇文章中的回答:如何处理 Codeigniter 模板?
在控制器中:
//Charge the view inside array
$data['body'] = $this->load->view('pages/contact', '', true);
//charge the view "contact" in the other view template
$this->load->view('template', $data);
在视图 template.php 中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
<title>Template codeigniter</title>
</head>
<body>
<div>
<?=$body?>
</div>
<div class="clear"></div>
<div>Footer</div>
</div>
</body>
</html>
$body 是视图联系人。
但现在我面临一个问题。如果我将 form_view 作为字符串传递给 $data['body'],则表单验证不起作用。有没有办法解决它?
谢谢。