gpt4 book ai didi

php - codeigniter 在 Controller 末尾加载 View

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

在 Ci 上,您可以直接从 Controller 的构造函数加载 View ,我正在加载页面的页眉和页脚(因为每个函数都相同)

class Add extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->view('header_view');
$this->load->view('footer_view');
}

function whatever()
{
//do stuff
}

}

但这会在加载我的函数之前加载页脚 View ,那么有没有办法在每个函数末尾“手动”加载 View 的情况下做到这一点?

最佳答案

我会在数据的主视图中添加页眉/页脚,或者使用模板库(我使用这个 one )。

如果在功能的主视图中;

// in view for html page
<?php $this->load->view('header'); ?>
<h1>My Page</h1>
<?php $this->load->view('footer'); ?>

关于php - codeigniter 在 Controller 末尾加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998293/

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