gpt4 book ai didi

将 View 作为字符串传递时,codeIgniter 表单验证不起作用

转载 作者:行者123 更新时间:2023-12-04 06:09:19 25 4
gpt4 key购买 nike

我目前正在学习 CodeIgniter 并将其用于一个小项目。我想制作一个模板,这样我就不需要为 View 编写重复的代码。我喜欢 jruzafa 在这篇文章中的回答:How to Deal With Codeigniter Templates?

在 Controller 中:

    //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);

在 View 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 是 View 联系人。

但现在我面临一个问题。如果我将 form_view 作为字符串传递给 $data['body'],则表单验证不起作用。有没有办法解决它?

谢谢。

最佳答案

尝试在模板本身中加载正文内容。这应该允许您对输出更有选择性:

在 Controller 中:

// Set the path to body content inside the $data array
$data['path_to_body'] = 'pages/contact';
$this->load->view('template', $data);

在 View 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>
<? $this->load->view($path_to_body) ?>
</div>
<div class="clear"></div>
<div>Footer</div>
</div>
</body>
</html>

关于将 View 作为字符串传递时,codeIgniter 表单验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7961161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com