file paths are wrong |
[eluser]GamingFusion[/eluser]
ok im creating the template for my website. I have a template folder in the views folder called SocialCrab. in there i have a index.php file, a style.css file, and an images folder that contains the logo image. I cant reference either the stylesheet or the logo image are these urls wrong Code: <link rel="stylesheet" type="text/css" href="style.css" /> and Code: <a href="#"><img src="images/logo.png" alt="logo" border="0"/></a> neither files will load in the browser
[eluser]WanWizard[/eluser]
References in images, stylesheets, anchors, etc are relative to the URL. So in the above example, if your URL is http://www.example.org/controller/method, the browser will try to load http://www.example.org/controller/style.css. Which probably doesn't exit. Don't use relative paths, use absolute paths using base_url().
[eluser]WanWizard[/eluser]
A bit of searching would have provided plenty of answers... I have all site assets (stylesheets, javascript, images, etc) in a subdirectory called assets: Code: <link rel="stylesheet" href="<?php echo base_url();?>assets/css/style.css" type="text/css" media="screen" /> This assumes your css files are in the directory 'assets/css' (where 'assets' is a subdirectory of the directory where your index.php is). Also, don't forget to update your .htaccess so it doesn't rewrite requests to files in the 'assets' directory.
[eluser]GamingFusion[/eluser]
how would i do the .htaccess part. i dont work with it much and i ahve tried googling it
[eluser]Isamtron[/eluser]
I suggest you use the absolute path. Your code will be cleaner and you'll save unnecessary function calls. Assuming your app assets folder is located under public_html: Code: <link rel="stylesheet" href="/assets/css/style.css" type="text/css" media="screen" />
[eluser]WanWizard[/eluser]
It is hardly ever a good idea in programming to hard-code something. And this is not an exception. As soon as you have to move things around, you'll have a major change on your hands. This is my .htaccess: Code: <IfModule mod_rewrite.c>
[eluser]GamingFusion[/eluser]
shouldnt this line do what i need it to do? Code: # do not rewrite requests for the standard asset files
[eluser]WanWizard[/eluser]
If that's all you need to exclude from rewriting, yes. For me, the condition filtering assets requests is the most important one. I need this only when running the setup (because there are no assets yet). By centralizing your assets in one directory, you also don't have to think about modifying your .htaccess when you introduce a new file type. This is important when you move the rules to httpd.conf (using .htaccess is expensive), you don't want to have to restart the (production) webserver if it isn't absolutely needed.
[eluser]mddd[/eluser]
I agree with Wanwizard: it's just good practice to build a system that will continue to work even if you add new stuff! So using /assets (of however you like to call it) is better than switching by file type. Also, don't forget you will still have to use complete paths in your view! If you try to load "assets/img/myimage.png" from a view, it will likely not work, unless you happen to be on the home page. Because the browser will request the file relative to the current location. See Wanwizard's first comment. |
Welcome Guest, Not a member yet? Register Sign In |