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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?