duanbai1027 2012-04-13 18:05
浏览 30
已采纳

将额外脚本从视图传递到标头

So I'm basically trying to pass the <link> and <script> tags into my original header file from a modules view file (which is displayed in the body of the page). How can I pass variables that include these references?

Currently I have just put extra <head></head> tags into my module's view, but it just feels messy and dodgy to do so, as that means the head tags are used up the top of the page, and also mid-way down.

Edit: Didn't realise that stack overflow edited out my tags that are crucial to this question! Sorry guys!

  • 写回答

2条回答 默认 最新

  • duanbozhong9689 2012-04-13 19:02
    关注

    It sounds like you are really in need of a Template setup for CodeIgniter. Here are links to some of my favorites:

    http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

    http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/

    And my personal favorite for simplicity:

    http://maestric.com/doc/php/codeigniter_template

    EDIT: Per @Sneaksta's question, here is how I add css scripts to my template:

    In my master template I have this code:

    <?php if (!empty($cssFiles)): ?>
    <?php foreach ($cssFiles as $styleSheet): ?>
        <link rel="stylesheet" media="screen" href="<?= base_url(); ?>styles/<?= $styleSheet; ?>" />
    <?php endforeach; ?>
    <?php endif; ?>
    

    Then in my controllers that might need to load different CSS files per function I do this:

    $cssFiles = array('style1.css', 'style2.css', 'style3.css');
    $this->template->set('cssFiles', $cssFiles);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!