dongyu5104 2014-04-10 15:13
浏览 354

CodeIgniter - 从控制器中的另一个函数加载视图

Here's the issue :

If I call, it loads my 'quizz' page.

But if I call (containing the same code), the view is messed up because of broken links (images, css, ...)

Here is the content :

public function index()
       $data['questions'] = getSettings();
       $this->load->view('quizz', $data);

If I call another function (, the layout fails :

public function start()
       $data['questions'] = getSettings();
       $this->load->view('quizz', $data);

As you know, CodeIgniter reads the URL like, so it should be good, right?

  • 写回答

2条回答 默认 最新

  • dqb77047 2014-04-10 16:02

    You want to call your CSS, JS and images using an absolute path. I suspect you are using a relative path. If you haven't already it's best to create a common header view and use base_url(). For example

    <!-- Load CSS -->
    <link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>css/style.css" />
    <!-- Load JS -->
    <script type="text/javascript" src="<?php echo base_url(); ?>js/script.js"></script>

    Obviously change the path to the files to be correct for your installation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 FOC simulink
  • ¥15 咨询一下有关于王者荣耀赢藏战绩
  • ¥50 MacOS 使用虚拟机安装k8s
  • ¥500 亚马逊 COOKIE我如何才能实现 登录一个亚马逊账户 下发新 COOKIE ..我使用下发新COOKIE 导入ADS 指纹浏览器登录,我把账户密码 修改过后,原来下发新COOKIE 不会失效的方式
  • ¥20 玩游戏gpu和cpu利用率特别低,玩游戏卡顿
  • ¥25 oracle中的正则匹配
  • ¥15 关于#vscode#的问题:把软件卸载不会再出现蓝屏
  • ¥15 vimplus出现的错误
  • ¥30 怎么使用AVL fire ESE软件自带的优化模式来优化设计Soot和NOx?
  • ¥15 Ubuntu20.04.4.LTS系统如何下载安装VirtualBox虚拟机?