dsgw8802 2016-01-15 04:07
浏览 28

使用codeigniter php加载多个视图

I have 4 pages in view such as

layout/header.php,
layout/header_assets.php,
user/main.php,
layout/footer.php

i want to load these multiple view so i have used this code in controller

$this->load->view('layout/header_assets');
    $this->load->view('user/main',$data);
    $this->load->view('layout/footer');

but i have got an issue :

<link rel="apple-touch-icon" href="http://localhost/game/assets/images/apple-touch-icon.png">
<html lang="en">

<head>
</head>

<body>
test
</body>
</html>
<footer>

</footer>

I want html code in proper way, header_assets load in head tag, footer load in body tag.

but right now if i load first header_assets and than load main.php. so header_assets load first after that main.php

I want it in this way

<html lang="en">

<head>
<link rel="apple-touch-icon" href="http://localhost/game/assets/images/apple-touch-icon.png">
</head>

<body>
test

<footer>

</footer>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • dsa456369 2016-01-15 04:16
    关注

    You can create a folder includes under view and create a page template and add the below code in page template-

    <?php $this->load->view('includes/header');
        $this->load->view($middle);
        $this->load->view('includes/footer');   
    ?>
    

    And in your controller you can just call the template and pass your data like below-

    $this->data['middle'] = 'public/existing_mem'; // view page to be included
     $this->load->view('includes/template',$this->data);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来