Welcome Guest, Not a member yet? Register   Sign In
referencing js and css
#1

[eluser]sergitin[/eluser]
hi
i need to know how to make a reference to a js or css scripts
into a interface page

sorry my english
#2

[eluser]Derek Allard[/eluser]
Code:
<link type="text/css" rel="stylesheet" href="/css/file.css" />
<script type="text/javascript" src="/js/file.js"></script>
#3

[eluser]sergitin[/eluser]
yeah, but i have a doubt
i make this references in the interface page
and this page is loaded from a controller page
so
the js and the css scripts most be under the controller folder, isn't it?
#4

[eluser]Derek Allard[/eluser]
No. the "/" at the beginning means "go to the top". So it assumes you have a "css" folder and a "js" folder right off the root, right beside your system folder, and your index.php file.
#5

[eluser]sergitin[/eluser]
do this means this
/system
...../application
...../css_folder
...../others
/user_guide

or this

index.php
/system
/css
/user_guide

????
#6

[eluser]Derek Allard[/eluser]
The second.
Code:
index.php
/system
/css
/user_guide
#7

[eluser]vitoco[/eluser]
if you have the CI app in a subfolder , and not directly in the root , you may use de base_url() function to give the full path to YOUR root folder , like this

Code:
<link type="text/css" rel="stylesheet" href="<?=base_url();?>css/file.css" />

then if you move the app to another folder , you must change only the the base_url in the config file and not the path to your resources in all the views

this also can be applied to an app in the root folder
#8

[eluser]Unknown[/eluser]
You can use

Code:
<link type="text/css" rel="stylesheet" href="<?=dirname(base_url());?>css/file.css" />

so the index.php won't be included in your link
#9

[eluser]Michael Wales[/eluser]
You don't need to use the dirname() function if your config.php is properly configured.

If you are using a .htaccess file you should set the index_page key to an empty string, which would keep base_url() from including that within the link.
#10

[eluser]Peter Ivanov[/eluser]
base_url() is fine for me




Theme © iAndrew 2016 - Forum software by © MyBB