My (header,footer) and js,css,image,favicon load only in index method not in other in codeigniter

戏子无情 提交于 2021-02-11 15:54:09

问题


I am new to code igniter and integrating bootstrap template with code igniter. i have created several pages in template already and try to integrate it with CI.

my css and js structure like below:

application
assets
         css/style.css
         js/min.js
         img/imagename.jpg

My controller file as below

     <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function index()
    {
        $this->load->helper('url');
        $this->load->view('templates/header');
        $this->load->view('home');
        $this->load->view('templates/footer');
    }
    public function services()
    {
        $this->load->helper('url');
        $this->load->helper('html');

        $this->load->view('templates/header');
        $this->load->view('services');
        $this->load->view('templates/footer');
    }
}

As per my understanding i need to create an different method for the different page so i can put it within header and footer. please let me know if i am wrong here.

I have created one folder named as templates in view and put create header.php and footer.php and put header and footer code in particular file.

my .htaccess file as below

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]

Than i creted a view named as home in view folder and put html code and include all js and css here like:

<link rel="stylesheet" type="text/css" media="all" href="assets/css/reset.css" />

And it work perfect.

But when i create another view as service and put css and js same as above than in my service view i cannot get data from header.php footer.php and also not load css or js or images.

And than i used url helper like below:

<script src='<?php echo $this->base_url();?>assets/js/jquery.colorbox-min.js'></script>

And it loads js files and css files but not get the proper view. and still header and footer files are not loaded in service view. So can i get any help from code igniter experts.


回答1:


This is cause error, view file load looks ok. Change this.

<script src='<?php echo $this->base_url();?>assets/js/jquery.colorbox-min.js'></script>

as following and try

<script src='<?php echo base_url('assets/js/jquery.colorbox-min.js');?>'></script>

make sure you have set your base_url in config.php as http://localhost/project_name/

If you getting still any error to load view files, post your error details here




回答2:


        RewriteEngine on 
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
 RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]


来源:https://stackoverflow.com/questions/39738286/my-header-footer-and-js-css-image-favicon-load-only-in-index-method-not-in-oth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!