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">
Related
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 work on my website but I have a problem with the links in the href.
My CSS and javascript files are in this folder (in the root of my site):
assets/stylesheets/file_css.css
For now the links of my href looks like this:
<link rel="stylesheet" href="./assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="./assets/fonts/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="./assets/stylesheets/custom.css">
<link rel="stylesheet" href="./assets/stylesheets/media-queries.css">
I call it in all my php files with :
require_once __DIR__.'/layouts/header.php'
Problem:
When I want to create a folder to sort my files eg views (folder found at the root of my site)
Looks like views/test.php
All href don't work, console error :
test.php:10 GET http://localhost/mywebsite/views/assets/bootstrap/css/bootstrap.min.css
test.php:11 GET http://localhost/mywebsite/views/assets/fonts/font-awesome/css/font-awesome.min.css
test.php:12 GET http://localhost/mywebsite/views/assets/stylesheets/custom.css
In fact, my CSS aren't in views folder.
I tried many things
1 - <link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.min.css">
error => test.php:10 GET http://localhost/assets/bootstrap/css/bootstrap.min.css
2 - <link rel="stylesheet" href="<?php echo __DIR__ ?>/assets/bootstrap/css/bootstrap.min.css">
error => test.php:10 Not allowed to load local resource: file:///C:/wamp/www/mywebsite/layouts/assets/bootstrap/css/bootstrap.min.css
I thought to put href="/mywebsite/assets/bootstrap/css/bootstrap.min.css" in the first link, it works locally but not on the server
I really need help, I start having too much PHP file at the root
Thank you
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');
I have got a project built in Zend-framework V1, where the link to another css file from a no-extensioned file is assigned in this way.
In the header file
<link rel="stylesheet" href="<?php echo $this->baseUrl() ?>/assets/user/css/login.css" type="text/css" media="all" />
But the public folder structure is like the below
public/assets/user(now this user is a file without any extension)
and when I open this "user" file I get the following line
../../packages/user/public/assets/user
I can find the login.css which is under
packages/user/public/assets/user/css/login.css
This is working fine in live but my local is not detecting the correct css.
Any help is highly appreciated. Many thanks in advance.
I use XAMPP and CI 2.14
(I know it's sounds ridiculous, but...) I don't know how to refer to a css file from a view. I've read and tried a lot of examples but, obviously I do something wrong...
<link rel="stylesheet" href="<?php echo base_url();?>css/main.css" type="text/css" />
The base url is: http://localhost/myapp/
Where should I put then main.css file (now is in the webroot/myapp/css folder), and how to reference it from a codeigniter view?
create folder assets:
path is: /assets/css/your_file.css
<link rel="stylesheet" href="/assets/css/your_file.css" type="text/css" />
Try to put the css folder inside the application folder, like this:
/yourapp/application/css/
And then
<link rel="stylesheet" href="<?php echo base_url();?>application/css/main.css" type="text/css" />