当我使用codeigniter url时,Materialise消失

时间:2017-12-15 16:19:44

标签: php html css codeigniter

我有一个奇怪的问题。我正在使用Materialiseiter和MaterialiseCSS。我想创建导航来创建菜单。问题是当我使用localhost / page时一切正常,导航栏是可见的,但是当我使用site.url时,页面看起来像materalize不包括在内。我不知道该怎么办。我可以在浏览器enter image description here

中找到包含URL的内容

localhost/page after forwarding 控制器:     

class main extends CI_Controller {

        public function __construct()
        {
        parent::__construct();
        $this->load->database();
        $this->load->view('head');
        $this->load->view('index');
        }
        public function index()
        {
        $this->load->model('quiz_model');
        $data['result'] = $this->quiz_model->get_data();
        $this->load->view('content/quiz', $data);
        }
        public function addquestion()
        {
            $this->load->view('content/addquestion');
        }
}

的index.php

<?php
$this->load->helper('html');
$this->load->helper('url');
?>
<nav>
  <div class="nav-wrapper">
    <a href="" class="brand-logo">Logo</a>
    <ul id="nav-mobile" class="right hide-on-med-and-down">
            <?php echo '<li><a href="' .site_url("main").'">web page</a></li>' ?>
            <?php echo '<li><a href="' .site_url("main/addquestion").'">Dodaj pytanie</a></li>' ?>      
    </ul>
  </div>
</nav>

head.php

<!DOCTYPE html>
<html>
<head>
      <!--Import Google Icon Font-->
      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <!--Import materialize.css-->
      <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

      <!--Let browser know website is optimized for mobile-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/materialize.min.js"></script>
    <title>Strona</title>
</head>
<body>
       <div class="container">

2 个答案:

答案 0 :(得分:0)

您需要设置您在网址中显示IP的基本网址。

配置/ config.php中

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

答案 1 :(得分:0)

您需要更改几行:

控制器

    ...
    public function __construct()
    {
    parent::__construct();
    $this->load->database();
    $this->load->helper('url');  // move url helper here, so it could be used on head view
    $this->load->view('head');
    $this->load->view('index');
    }
    ...

head.php

<!DOCTYPE html>
<html>
<head>
    <!--Import Google Icon Font-->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!--Import materialize.css-->
    <link type="text/css" rel="stylesheet" href="<?php echo site_url() ?>css/materialize.min.css"  media="screen,projection"/>

    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="<?php echo site_url() ?>js/materialize.min.js"></script>
    <title>Strona</title>
</head>
<body>
    <div class="container">