I have tried base_url() function, But I didn't understand where am I wrong?
I have also mentioned - $this->load->helper ('URL'); in function abc() in controller.
Here is my code,
<link href="<?PHP echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/CSS"/>
Use below code to link your css :
<link href="<?php echo base_url(); ?>assets/css/style.css" rel="stylesheet" type="text/css">
make sure you have configure the CI configuration properly :
CONFIG.PHP
$config['base_url'] = 'http://localhost/your_project/';
$config['index_page'] = '';
AUTOLOAD.PHP
$autoload['helper'] = array('url');
It is because of the way you are referencing the css file. You can use this:
<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Or you can use this:
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
Notice the / at the start of the link, this means the browser will look from the base of your website url (your domain). If you miss it out it will use the relative part of the url, so if you are referencing a controller it will assume this is a sub folder for the location of the css file too.
You are better off with the base_url format given first, if you are using a local host for development then you will not have any problems with the url base. If you app is moved to a sub folder on another site or with a sub domain etc you will not have any problems either.
So base_url is the way to go here. More info in the docs.
http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url
I am thinking you have not set tour base_url if your base url shows Ip address in links your css will not work
You need to set this value
$config['base_url'] = 'http://localhost/yourproject/';
Head
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Make sure your assets folder out side of application
application
assets
A good thing is to also autoload url helper lower case.
$autoload['helper'] = array('url');
Related
This error occurs when I enter this code
<link rel="stylesheet" href="<?php echo base_url("asserts/css/bootstrap.min.css"); ?>" integrity="" crossorigin="anonymous">
Integrate Bootstrap on CodeIgniter.
These answers are not working for me
For getting correct result you should set base_url first inside application/config/config.php
like below
$config['base_url'] = 'http://localhost/codeigniter/';
//codigniter is demo project. set your own;
after that you should check weather you have loaded url helper or not.
to do that go to application/config/autoload.php and set the url like below
$autoload['helper'] = array('url');
finally check you have successfully set directory of css file inside base_url() function. hope that, it will work
Set the base_url in config.php
$config['base_url'] = 'http://localhost/FirstApp/';
Reason if you do not some assets and links will not work.
Use lower case name for your directories and your path.
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.min.css"); ?>" integrity="" crossorigin="anonymous">
some platforms are case sensitive.
IM trying to load some css directly within my view file, but its not working.
in my view file I have this.
<link href="<?php echo base_url(); ?>assets/css/core.css" rel="stylesheet" type="text/css" />
The assets folder is at the same level as Application
when I view source on the webpage it shows me this
demo.example.com/assets/css/core.css
but when i click the link to see if it's working the url becomes this...
http://demo.example.com/admin/demo.example.com/assets/css/core.css
not sure what I am doing wrong? Should I be adding something to my htaccess file?
Thanks in advance.
You don't need to include the base_url() in your path because the webserver already knows your at www.example.com/admin and auto includes that.
Just use
<link href="/assets/css/core.css" rel="stylesheet" type="text/css" />
Edit: Or actually you need to include the http: prefix on your base_url like wolfgang1983 said.
See this answer on CSS absolute and relative link paths. https://stackoverflow.com/a/17621358/3585500
I am struggling with linking all my files : css, JavaScript, bootstrap, images etc... On my local server works everything fine. When I upload to my web server I got this error...and I know it is because of the path that I have. It searches everything on my local. and I am using Codeigniter framework, so I have no idea what the path should be when I put it online.
Example :
<link rel="stylesheet" type="text/css" href="<?php echo css_folder_url('reset.css'); ?>" media="screen"/>
<link href="<?php echo base_url() ?>web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
This is how I need to link in this framework
Maybe I should change something in my host file :
andreaportfolio.local
::1 andreaportfolio.local --> maybe should be .com instead of local
Photo about the error message
here there is how things should work in a small step-to-step guide:
Create a folder called 'assets' in /wamp/www/yourProjectDirectory [In WAMP server];
Edit the config.php in yourProjectDirectory/application/config directory as:
$config['base_url'] = 'http://localhost/yourProjectDirectory/';
<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
Create the controller as Boots.php;
Create the view file as samplebootstrap.css
<link href="<?php echo base_url('assets/css/bootstrap.css');?>" rel="stylesheet">
Go to the web browser and type:
http://localhost/yourProjectDirectory/index.php/boots/getBoots
Here you can find a dedicated thread on the topic:
https://forum.codeigniter.com/thread-1146.html
Hope this could help,
L.
This error usually means that the specific file was not found. So either the path is wrong or the file is not present where you want it to be. Try to access it by entering source address in your browser to check if it really exists there. Browse the directories on the server to ensure that the path is correct. You may even copy and paste the relative path to be certain it is correct.
There can be a '/' missing as well, for example:
<link href="<?php echo base_url() ?>web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
could be
<link href="<?php echo base_url() ?>/web/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="<?= base_url('asset/css/font-awesome.css');?>" rel="stylesheet" type="text/css"/>
I have applied css in a view file with head tag.
I am begginer in a codeigniter so,anyone have solutions for me.
You have misspelled bae_url() instead base_url().
Change it to
<link href="<?php echo base_url('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css');?>">
and in APPPATH . 'config/config.php' set
$config['base_url'] = 'http://localhost/greenschool/';
Im guessing you forgot an s after asset since your other links use assets folder. Also in the screenshot you have typos in link for dataTables.bootstrap.css.
I am kinda newbie to CodeIgniter. Somehow I set up the development environment and ready to go. But loading the CSS, JS into page seems a lot more confusing. Before moving, I googled a lot but the base_url solution is not helping.
Part of View :
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
<link href='css/fullcalendar.css' rel='stylesheet'>
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
<link href='css/opa-icons.css' rel='stylesheet'>
<link href='css/uploadify.css' rel='stylesheet'>
Controller :
public function dashboard()
{
$this->load->helper('url');
$this->load->view('templates/css_styles');
$this->load->view('templates/top_bar');
$this->load->view('templates/left_menu');
$this->load->view('pages/dashboard');
$this->load->view('templates/footer');
$this->load->view('templates/js_end');
}
public function index()
{
$this->load->helper(array('form'));
$this->load->view('login');
}
route.php :
$route['default_controller'] = "welcome/dashboard";
$route['404_override'] = '';
$route['dashboard'] = 'welcome/dashboard';
If I put the dashboard method as default controller, the page is loading fine. But when I change it to just welcome, which is a login form and redirect to welcome/dashboard, the page doesn't load any CSS. Just all HTML texts. The dashboard page is just pure HTML, no PHP code written yet.
Please help me what might causing this.
What's wrong with base_url()?
<link href="<?php echo base_url('css/bootstrap-responsive.css')?>" rel="stylesheet">
make sure you load URL helper, I recommend autoloading it: go to application/config/autoload.php and add it to the helper array:
$autoload['helper'] = array('url');
You can use the link_tag() in html_helper.php to help get the paths correct.
First load the helper (I usually have it autoloaded)
$this->load->helper('html');
Then you can reference css like this:
echo link_tag('css/bootstrap-responsive.css');
The advantages are the function tries to build the correct absolute URL to the css file and it automatically sets the rel attribute to stylesheet and the type attribute to text/css.
Also you should have Chrome, Safari, or Firebug for Firefox so that you can inspect the code and see if the CSS files are being loaded or if they are not found. This will help with debugging.
Make sure you have a leading slash before your css folders:
<link href="/css/bootstrap-responsive.css" rel="stylesheet">
And make sure that the files are indeed located in /css off your web root, not inside the application folder.
first you need load helper url
$this->load->helper('url');
and then on controller
$this->data =site_url()."your css file";
then on your view
<link rel="stylesheet" type="text/css" href="<?php echo $css; ?>">
its simple.you can view full article load css/js