Aravinth E
Aravinth E

Reputation: 491

Base_url() not working on codeigniter

I am using CodeIgniter bootstrap stylesheet link URL can't work properly. Controller code

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

class Welcome extends CI_Controller {

    public function index()
    {
        $this->load->helper('url');
        $data['title'] = "Login Home";
        $this->load->view('home',$data);
    }
}

HTML Code

<div class="container">
    <div class="row">
        <div class="col-lg-offset-4 col-lg-4">
            <div class="well">
                <h3>welcome</h3>
            </div>
        </div>
    </div>
</div>

CSS link code

<link href="<?php echo base_url("register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">

Upvotes: 0

Views: 1553

Answers (3)

Parvez Ahmed
Parvez Ahmed

Reputation: 650

in config.php set this line

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

root directory set this way

application
system    
bootstrap-3.3.6

Upvotes: 2

Mahesh
Mahesh

Reputation: 93

ensure that you are using .htaccess file in your codeigniter application.create one folder assets.place your css file in assets folder.after that link that file like this,

in application folder config file paste this,

$root = 'http://' . $_SERVER['HTTP_HOST'];

$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);;

$config['base_url'] = $root;







<link href="<?php echo base_url("assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">

if you are not using htaccess file,

<link href="<?php echo base_url("index.php/assets/register/application/bootstrap-3.3.6/css/bootstrap.min.css"); ?>" rel="stylesheet">

try this....

Upvotes: 0

user4419336
user4419336

Reputation:

Place assets out side of application. Reason the .htaccess in application folder blocks it.

application
assets
assets > bootstrap > css > bootstrap.css
assets > bootstrap > js > bootstrap.js
system
index.php

First I would suggest

config/autoload.php

$autoload['helper'] = array('url');

then

config/config.php Set your base url

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

Upvotes: 3

Related Questions