0

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.

Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37

2 Answers2

0

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

Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
  • Thanks for the answer. but my js and css file loaded with both the code as above. but the header and footer cant load with service method. that i can't understood – Devsi Odedra Sep 28 '16 at 05:34
  • when i run http://localhost/cinew1/welcome/services than it shows the content which in services views. and also give effect of css and js. But i cant load content which is in my footer.php and header.php and also i dont know hot to use base_url for images so images are also not loading in it. – Devsi Odedra Sep 28 '16 at 05:49
0
        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]
Reuben Gomes
  • 878
  • 9
  • 16
  • i use wamp server – Devsi Odedra Sep 28 '16 at 05:50
  • nice click on the wamp icon in your taskbar >apache>apache modules>(scrolldownand select) rewrite module restart wampp services – Reuben Gomes Sep 28 '16 at 05:51
  • worked? a good tip use the autoload file to load helper/libraries if your gonna use it throught your application save you space and the trouble to copy paste it again and again ....unless you know how to use __ constructs() – Reuben Gomes Sep 28 '16 at 05:55
  • i already done this. but my problem is that why my images, header, footer not loading in services views.?? – Devsi Odedra Sep 28 '16 at 05:56
  • base_url() set? in cofig file – Reuben Gomes Sep 28 '16 at 05:57
  • `$config['index_page'] = '';` `$config['base_url'] = 'http://localhost/real';` – Reuben Gomes Sep 28 '16 at 05:59
  • my base url is $config['base_url'] = 'http://localhost/cinew1/'; my problem now only is why templates/header.php templates/footer.php and images not loading. – Devsi Odedra Sep 28 '16 at 06:01
  • in your images you load it the same way you call your external scripts and your css files – Reuben Gomes Sep 28 '16 at 06:01
  • hmm spelling mistake may be? check folder names also ... view names are case sensitive so if your file name starts with a capital call it with a Capital – Reuben Gomes Sep 28 '16 at 06:02
  • i load images as – Devsi Odedra Sep 28 '16 at 06:02
  • yea but is neater to do – Reuben Gomes Sep 28 '16 at 06:03
  • hmm spelling mistake may be? check folder names also ... view names are case sensitive so if your file name starts with a capital call it with a Capital your view files are in template folder check the folder name is same – Reuben Gomes Sep 28 '16 at 06:06
  • same thing work in index method as above i put code of my controller. you can see. – Devsi Odedra Sep 28 '16 at 06:07
  • change your htaccess rule `RewriteRule ^(.*)$ ./index.php/$1 [L]` to `RewriteRule ^(.*)$ index.php?/$1 [L,QSA] ` QSA and a ? after index.php – Reuben Gomes Sep 28 '16 at 06:16
  • when i hit url as http://localhost/cinew1/welcome/index than it will not load any css or images or js. but when i load http://localhost/cinew1 it will load perfect – Devsi Odedra Sep 28 '16 at 06:17
  • or just replace your htaccess with mine `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]` – Reuben Gomes Sep 28 '16 at 06:17