Welcome Guest, Not a member yet? Register   Sign In
Adding Javascript and CSS to an application
#1

[eluser]ronn[/eluser]
I'm new to CodeIgniter and would like to add my JavaScript and CSS the CodeIgniter way. Where in the directory structure would I place the physical files? How would I include them in my view?
#2

[eluser]maria clara[/eluser]
[quote author="ronn" date="1265768719"]I'm new to CodeIgniter and would like to add my JavaScript and CSS the CodeIgniter way. Where in the directory structure would I place the physical files? How would I include them in my view?[/quote]

you can put your JS and CCS files in a separate folder outside your system folder or anywhere you want to put it. And then you can access it in the system/view/templates/header.php if you have a master page as i have.

what matter is your gonna call it and place it in the <head></head> of your view.

like this for example:

Code:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? if (isset($ptitle)) echo $ptitle." / " ?>ComUnion ERP ©</title>
<link rel="stylesheet" href="<?=base_url()?>css/default/style.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>css/default/calendar.css" />
<link rel="stylesheet" href="<?=base_url()?>css/default/ui/ui.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>css/default/ac/autocomplete.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>css/flexigrid/flexigrid.css" type="text/css" />

<link rel="stylesheet" href="<?=base_url()?>css/jqthemes/ui.jqgrid.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>css/jqthemes/smoothness/jquery-ui-1.7.2.custom.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>lib/jquery/src/css/jquery.searchFilter.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>lib/jquery/src/css/ui.multiselect.css" type="text/css" />
<!--[if lt IE 7]>
    <link rel="stylesheet" href="<?=base_url()?>css/default/style.ie6.css" type="text/css">
<![endif]--&gt;
&lt;!--[if IE ]>
    &lt;link rel="stylesheet" href="&lt;?=base_url()?&gt;css/default/style.ie.css" type="text/css"&gt;
<![endif]--&gt;
&lt;link rel="shortcut icon" href="&lt;?=base_url()?&gt;favicon.ico" /&gt;
&lt;link rel="icon" href="&lt;?=base_url()?&gt;favicon.ico" type="image/x-icon" /&gt;


it is like accessing in a external file in native html webpage.
#3

[eluser]cjaffar[/eluser]
hey guyz. this is second time i'm seeing the base_url() thing. what is that? i try put it in my code and it breaks with undefined function. i check whole codeigniter api and i find BASEPATH, but when i include it, it fails completely. i'm using windows, may be it doesn't like the appended c:\ path and /. PLEASE HELP.
#4

[eluser]LuckyFella73[/eluser]
@cjaffar

You need to load the URL-helper to use
Code:
&lt;?php echo base_url(); ?&gt;
#5

[eluser]cjaffar[/eluser]
thanks. that was great. after discovering codeigniter, i wonder why would any1 ever go for anything else ... all the crap joomla, etc.




Theme © iAndrew 2016 - Forum software by © MyBB