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" />
Related
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">
I am new to the CodeIgniter, however when i try to link bootstrap files to my project blank(white) screen appears.
<link rel="stylesheet" type="text/css" href="<?php echo base_url("assets/css/bootstrap.min.css");?>" >
I put all bootstrap files inside assets folder which is in the same level as root directories as follows
application
assets
css
bootstrap.min.css
system
I tried alternative such as
<link rel="stylesheet" type="text/css" href="<?=base_url();?>assets/css/bootstrap.min.css" >
And
<link rel="stylesheet" type="text/css" href="<?php echo link_tag("assets/css/bootstrap.min.css")?>" >
none of these seems to work, what should i do? someone help me please!
Let's suppose you have a file in the view folder (application/views) called home_view.php and another file in css folder(application/assets/css/bootstrap.min.css).
In order to link your css file into the view you need to add this line in your home_view.php:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/assets/css/bootstrap.min.css"/>
If your assets folder is in the same level directory as application folder you can make a constant in constants.php(application/config/constants.php) file:
define('MY_ASSETS', 'assets/');
and your link will be:
<link rel="stylesheet" type="text/css" href="<?php echo MY_ASSETS; ?>css/bootstrap.min.css"/>
I am currently working on a admin backend and now want to move some pages into different folders (so I do not have all scripts in one folder).
Structure looks like this:
/
/theme/assets/...
/templates/head.php
/templates/foot.php
/top/index.php
/index.php
In head.php there are some stylesheets added like this
<link href="theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
This works fine for files in the root folder (e.g. index.php), but when I use the same head.php in /top/index.php it does not work because the path is wrong.
Is it somehow possible to properly include the stylesheets etc. while having the scripts in different folders?
Greetz,
Just specify the root identifier (/) at the beginning of the href attribute:
<link href="/theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
Try this,
<link href="../theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
In /top/index.php
OR
<link href="<?php echo $_SERVER['DOCUMENT_ROOT'] ?>/theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
This code can be used in any page. The $_SERVER['DOCUMENT_ROOT'] points to the root.
Use '../' to reference the folder above and work your way back.
e.g
<link href="../theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
folder structure
/
|--index.php
+--includes
|--header.html
+--css
|--style.css
I have 2 subfolders in my main project folder. One is a folder called 'includes' and the other one is called 'css'.
I have my
-index.php file in the main folder
-header.html in my 'main/includes' folder
-style.css in my 'main/css' folder
My index.php includes the header.html like this:include_once('includes/header.html'); (this Works!)
My header.html file links the css like this:<link href='../css/style.css' type='text/css' rel='stylesheet'/>
(this does NOT work!)
I don't understand why the css file is not loaded.
I have tried using the base tag, although I'm not sure I'm using it right.
<base href="http://localhost/main" /> (this is NOT working)
You should try using
<link href='css/style.css' type='text/css' rel='stylesheet'/>
As index.php and the css folder lie at the same level.
With
<link href='../css/style.css' type='text/css' rel='stylesheet'/>,
you are asking your server to look after the style.css in upper level directory of index.php which does not exist.
You can also use / because, it points do the document root of the website.
<link href="/css/style.css" type="text/css" rel="stylesheet" />
I don't think you understand how include works. Essentially the code in the referenced file will be copied into the main file, and then processed. So if you're including it into index.php, then you want to reference the CSS file accordingly.
The following should work:
<link href="/css/style.css" type="text/css" rel="stylesheet" />
You'll find it is the most easy to just use absolute paths when using HTML, that way the above like will still be valid, even if you copy it to a file that is in within a folder besides the root.
$siteurl ="http://localhost/project";
(store this variable in config file so that you can use globally)
<link href='../css/style.css' type='text/css' rel='stylesheet'/>
will be changed to
<link href='<?php echo $siteurl;?>/css/style.css' type='text/css' rel='stylesheet'/>
just change from <link href='../css/style.css' type='text/css' rel='stylesheet'/> to <link href='css/style.css' type='text/css' rel='stylesheet'/>
If you are trying to add CSS in html file using PHP require:
<style><?php require("css/style.css");?></style>
Note: <style> tag is important otherwise it will echo plain text
I am new to php, but suspect there is a simple solution that I am not aware of.
I have made a template for the header on every page, but when the user loads pages the css page changes in relation to their current page.
How do I have php track how many levels up in a folder the user is so I can pull the css from anywhere in the website?
<link rel="stylesheet" href="../templates/css/css.css" type="text/css" />
That is my current link to css, but for a page further down in folders I need it to add additional ../
You should use an absolute path from the root of the website (note, no ".." just a "/"):
<link rel='stylesheet' href='/templates/css/css.css' type='text/css' />
Will always work, as long as your css is at:
http://yourwebsite.com/templates/css/css.css
you shouldn't be using a relative path then. Why not just do something like:
<link rel="stylesheet" href="http://www.mysite.com/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />
whichever suits your needs - since you may be working locally and have a strange file structure, or a shared style directory for example
The best method is to use:
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />