Views - Stylesheets, Javascript, Images - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Views - Stylesheets, Javascript, Images (/showthread.php?tid=35786) Pages:
1
2
|
Views - Stylesheets, Javascript, Images - El Forum - 11-10-2010 [eluser]_chris[/eluser] I moved the project I was working on into the code igniter framework. I have my XHTML in the view, and it loads fine. But the javascript etc does not. I have moved the javascript, images, and stylesheet folder into the same folder as my index.php which is loaded by the controller. But the javscript etc isn't being loaded, for example I have: Quote:<*script src="javascript/jquery-1.4.2.min.js">(With out the * at the beginning) Which is in my javascript folder which is in the same folder as my index.php. Am I meant to place the stylesheets etc somewhere else? Since I have moved my project to code igniter do I have to change the src location of everything ? Views - Stylesheets, Javascript, Images - El Forum - 11-11-2010 [eluser]tonanbarbarian[/eluser] use absolute links not relative the problem is that if you are removing the index.php from the url then you might have common urls that look like this http://example.com/welcome - goes to the default method i.e. index or the controller welcome http://example.com/welcome/home - goes to the method home in the controller welcome http://example.com/article/show/3125 - goes to the controller article and calls the show method with a parameter of 3125 Now if you use a relative link such as javascript/jquery.js on each of those pages the browser will resolve these paths to http://example.com/welcome/javascript/jquery.js http://example.com/welcome/home/javascript/jquery.js http://example.com/article/show/3125/javascript/jquery.js so change your script tag to the absolute url Code: <* script src="http://example.com/javascript/jquery.js"> Views - Stylesheets, Javascript, Images - El Forum - 11-11-2010 [eluser]PeterGreffen[/eluser] If you are using a .htaccess file to (e.g.) get rid of your index.php, be sure to include your css, script and assets folders too... In my example, I have included uploads, captcha, logs, style, images and js... Code: RewriteEngine on Did you solve the problem? P. Views - Stylesheets, Javascript, Images - El Forum - 11-12-2010 [eluser]_chris[/eluser] I put the .htaccess file in the same folder as my XHTML, images etc. Now I get a "500 Internal Server Error" when trying to load the website. I don't actually understand what it is you gave me does exactly. I don't understand why I should get rid of my index.php ? And in regards to setting an absolute URL. I have a WAMP setup and I have the project hosted on my local computer. I don't actually have the domain for the project yet, nor do I want to point it to my computer. So if I was to use absolute URL's I have to find a way of getting it to work on my local machine, for that domain to point to the localhost/folder (not sure how to do that.) I wasn't using a .htaccess file before. Thanks very much for your help. Views - Stylesheets, Javascript, Images - El Forum - 11-12-2010 [eluser]InsiteFX[/eluser] The .htaccess file should go into your root folder were your index.php file is. InsiteFX Views - Stylesheets, Javascript, Images - El Forum - 11-12-2010 [eluser]_chris[/eluser] I put my .htaccess with my index.php along with the system folder which has all the code igniter folders and files within it. And I am getting: "500 Internal Server Error". Views - Stylesheets, Javascript, Images - El Forum - 11-12-2010 [eluser]matt.asbury[/eluser] I have created an assets folder in the same place as the index.php which contains other subfolders including images, js, css. This means that when I amend my .htaccess file to allow access to the folder, I only have to allow this one folder to gain access to all the other folders. I can also keep adding more folders without having to amend the .htaccess file. I have this line in my .htaccess file: Code: RewriteCond $1 !^(index\.php|assets|robots\.txt) Now when I want to access something in one of these folders I reference it absolutely rather than relatively like this: Code: <link type="text/css" rel="stylesheet" href="/assets/css/reset.css" /> Code: Options +FollowSymlinks Views - Stylesheets, Javascript, Images - El Forum - 11-12-2010 [eluser]InsiteFX[/eluser] Take off the first / see below and see if it works. Code: <link type="text/css" rel="stylesheet" href="assets/css/reset.css" /> InsiteFX Views - Stylesheets, Javascript, Images - El Forum - 11-14-2010 [eluser]_chris[/eluser] It might be outside of the knowledge you guys have. But maybe I am thinking there is something wrong with my httpd.conf. As soon as I said one line with "Rewrite" at the beginning I get the 500 server error. My complete .htaccess is: Code: Options +FollowSymlinks Which is located my www folder. I do have "AllowOverride All" but above it I have: Code: <Directory /> Should AllowsOverride be set to All instead of None? I don't know that much about the apache config obviously. Views - Stylesheets, Javascript, Images - El Forum - 11-14-2010 [eluser]dudeami0[/eluser] The base_url() function from the url helper is what I use to make my script locations absolute. Just do: Code: <*script src="<?php echo base_url(); ?>location/of/script.js" type="text/javascript"><*/script> Its what works for me, and doesn't rely on htaccess (Whichs seems to make a 500 Internal Server error everytime I look at it). Hope that helps Edit: Also with the 500 error your getting, might be rewrite is not enabled in your apache. Check that out first :p |