加载问题 css CodeIgniter 中的图像和 js

loading issue css Images and js in CodeIgniter

当 class 管理员加载默认调用的 index()。 css 和 js 在仪表板视图上加载,但是当我加载 post add_post CSS 时,JS 和图像未加载。 我在两个视图文件上放置了相同的代码。仪表板和 add_post 这是我的控制器。

class Admin extends CI_Controller {

  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $this->load->view('dashboard');
  }

  public function Post()
  {
    $this->load->view('add_post');
  }

}

config.php

$config['base_url'] = 'http://localhost/timesofeducation';

autoload.php

$autoload['helper'] = array('url', 'form', 'html', 'captcha', 'string');

当我加载 index() 时 css url 在检查元素时显示。 http://localhost/timesofeducation/css/style.css

但是当我加载时。 post() css url 在检查元素时显示。 http://localhost/timesofeducation/Admin/css/style.css

Admin Class 自动添加。

在 base_url 中错过了 /。试试这个

$config['base_url'] = 'http://localhost/timesofeducation/';

并确保您已使用 link 之类的资源

<?php echo base_url('css/style.css');?>