dongyu5104 2014-04-10 15:13
浏览 354
已采纳

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

Here's the issue :

If I call www.mysite.com/quizz, it loads my 'quizz' page.

But if I call www.mysite.com/quizz/start (containing the same code), the view is messed up because of broken links (images, css, ...)

Here is the content :

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

If I call another function (www.mysite.com/quizz/start), the layout fails :

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

As you know, CodeIgniter reads the URL like www.mysite.com/class/method, 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了