combat the asset_helper and base_url |
[eluser]aioon[/eluser]
Hello people, as I introduced in "Introduce your self" thread, I have maybe a real cool solution for one real annoying job! For a few days ago, I started to work with Codeigniter and I love it to work with but today I came across with a problem, which costs me a lot of time... I am using the routing functionality of ci with a .htaccess file: http://codeigniter.com/wiki/mod_rewrite/ it works great... until I implements some files, js, css, images... and damn, when I go to <url>/controller/method no of this files was included or implemented to the view... so I began to search for a solution and I found things like: Code: <img src='<?=base_url()?>images/your_image.jpg' alt='Your Alt' /> or to use helper like: http://codeigniter.com/wiki/Asset_Helper/ http://shawnmccool.com/2009/11/23/managi...deigniter/ Everything was a solution, but it costs so much time everytime to write base_url etc, and a little bit of performance... I try to find a better solution in serps, but i didn't... all tutorials and examples use the solutions above... So here is my solution, to combat the solutions above and to save a lot of time and a little bit of performance... So what we have todo: This is our default directory structure: Quote:system now we create a new directory in the same directory for e.g. we will call it assets and then we create 3 new diretories in this new directory css, js and images and now we have this directory structure: Quote:system so put your image files now in /assets/images and javascript files in /assets/js/ and css files in /assets/css Quote:system ok, and now we take this .htaccess file http://codeigniter.com/wiki/mod_rewrite/ and we put it in the same directory where assets, system and index.php are! Quote:system fine, and now we edit any view file we like where for e.g this is present: Code: <link rel='stylesheet' href='<?=base_url()?>css/your_style_sheet.css' type='text/css' /> so it was the past, today we will do it better! just delete <?=base_url()?> Code: <link rel='stylesheet' href='css/your_style_sheet.css' type='text/css' /> and in the code with js and images and then save it! open now your .htaccess file and put this combat the asset_helper and base_url rewrite line in the top of the file! Quote: #combat the asset_helper and base_url so your .htaccess file will be like this now: Code: <IfModule mod_rewrite.c> that the combat, we won =) and now when you visit <url>/controller/method alle the images, js and css files will be implemented and you will get what you want! thats my solution, how i combat the asset_helper and base_url and how i|we will save a lot of time in the future how you can see, you can implement any file-type you want! swf, avi etc. etc. if you need for e.g. swf files you have to create a new directory and call it flash in assets directory, after that you have to edit your .htaccess combat line, just add the attribute RewriteRule (css|js|images|flash)/(.*)$ assets/$1/$2 [L][/quote] then you can easy implement it in any view you want! Code: <embed src="flash/somefilename.swf" width="550" height="400"> and of course you can use subdirectories without deep limitation Code: <embed src="flash/videos/somefilename.swf" width="550" height="400"> how simple is that? hehe =) So people, I hope I build a real usefull solution and I hope you could understand me what I am trying here to explain My english isn't so good at this moment Have fun with this solution Thats my way... Regards Alex |
Messages In This Thread |
combat the asset_helper and base_url - by El Forum - 05-07-2010, 05:18 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:21 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:32 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:49 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:51 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:53 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 06:57 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 07:09 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 07:16 PM
combat the asset_helper and base_url - by El Forum - 05-07-2010, 07:25 PM
combat the asset_helper and base_url - by El Forum - 05-08-2010, 04:54 AM
combat the asset_helper and base_url - by El Forum - 05-08-2010, 02:28 PM
combat the asset_helper and base_url - by El Forum - 05-18-2010, 09:14 AM
combat the asset_helper and base_url - by El Forum - 05-18-2010, 11:02 AM
|