Welcome Guest, Not a member yet? Register   Sign In
Including .css and .js problem. Help please :(
#1

[eluser]Unknown[/eluser]
Hello guys,

I'm a Codeigniter noob and I've been using it for about 2 weeks. I decided to create some pages and follow some tutorials over the net and they helped. The problem is, there's not one thread in this forum that has helped me yet.

I've read in here that the views folder is relative to 'index.php' so that's why it's better of to put the .css and .js files in the same folder as 'index.php'.

So here my problem arises. I have 2 javascript (containing jQuery UI) and 1 .css file at the moment. I tried putting these files in the views folder, included them... didn't work. So what I did was, on the same folder as index.php, I created a folder named 'scripts'. Here I put all the images, .js, .css files I had. I tried including them like :

{script} type="text/javascript" src="<?php echo base_url();?>scripts/js/jquery-1.4.4.min.js">{script}


And I also autoloaded the url helper so I'm guessing the base_url() is functioning properly. My base_url() is 'http://localhost/ci/' wherein ci is the CodeIgniter folder.
I'm using the Xampp server.

What am I doing wrong?

I also did this: $config['index_page'] = ''; and also created a .htaccess file containing

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>

to disable the index.php from being needed in the URI. Maybe that's causing the problem?

I know it isn't working because a simple

$(document).ready(function(){alert('Hello');})

isn't working.

Also, do I have to initiate this? $this->load->library('javascript'); in order for my .js to work?

Please help Sad

EDIT:

I kinda got the .css working, although not fully. I changed my .htaccess file to this:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|scripts|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>

If you observe, I added the scripts folder there. The scripts folder contains 2 subfolders: the css (containing my .css and images which were showed), the js folder (containing jQuery 1.4.4.min.js and a jQuery UI which is related to my .css file)


Having the .css working, the jQuery/javascript on the other hand still does not seeing that the $(document).ready function doesn't still trigger and some effects while on hover do not appear.
#2

[eluser]InsiteFX[/eluser]
Download this:
Phil Sturgeon - Asset Library

InsiteFX
#3

[eluser]masdevid[/eluser]
this is my folder
+www
-my_site
+application
+system
+user_guide
+resource
-img
-css
-js

on site_view.php, i write this
Quote:&lt;base href="&lt;?php echo $this-&gt;config->item('base_url') ?&gt;" />
&lt;link rel="stylesheet" type="text/css" media="all" href="resource/css/firefox_style.css" /&gt;
&lt; script type="text/javascript" src="resource/js/jquery.js" &gt; &lt;/ script &gt;

It's working for me to run jQuery and CSS.
Hope this help.
#4

[eluser]osci[/eluser]
Another htaccess, as in the examples of removing index.php is
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Try this. It basically says redirect anything to index.php except if a specific folder or file is specified.

On the other hand if you add js after \text|css doesn't it work?

@insiteFx: Why would he need an assets library when he accomplishes this easier?




Theme © iAndrew 2016 - Forum software by © MyBB