CodeIgniter Forums
Getting feet wet-- couple of "best practice" questions - 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: Getting feet wet-- couple of "best practice" questions (/showthread.php?tid=29395)

Pages: 1 2


Getting feet wet-- couple of "best practice" questions - El Forum - 04-13-2010

[eluser]Fumigator[/eluser]
Once I changed from using a full url on my image paths to a relative path, I ran into the problem where if index.php is not in the url, the img path goes wrong. Any solution to that?


Getting feet wet-- couple of "best practice" questions - El Forum - 04-13-2010

[eluser]frost9928[/eluser]
I opted to use a pre-made .htaccess file which works really well and doesn't get in the way when it comes to images and other such things.

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

Not my work by the way found it through Google and can't find it again to save my life but it works great.


Getting feet wet-- couple of "best practice" questions - El Forum - 04-14-2010

[eluser]mddd[/eluser]
@Fumigator:
If you use urls like css/mycss.css then yes that is a problem because a file that is accessible from / will not be accessible from /mycontroller/mymethod.
I always use "semi relative" paths. Like /css/mycss. They are easy to type and read in your view and have no problems if you change domains or subdomains.
I know, it is a bit less flexible because you can't put the whole CI structure in a folder but it it very rare that I want to do that.


Getting feet wet-- couple of "best practice" questions - El Forum - 04-19-2010

[eluser]Fumigator[/eluser]
[quote author="mddd" date="1271245076"]@Fumigator:
If you use urls like css/mycss.css then yes that is a problem because a file that is accessible from / will not be accessible from /mycontroller/mymethod.
I always use "semi relative" paths. Like /css/mycss. They are easy to type and read in your view and have no problems if you change domains or subdomains.
I know, it is a bit less flexible because you can't put the whole CI structure in a folder but it it very rare that I want to do that.[/quote]

OK... yeah, this seems to work OK. I'll have to modify my config for different environments but I kind of have to do that anyway.


Getting feet wet-- couple of "best practice" questions - El Forum - 04-20-2010

[eluser]dejitaru[/eluser]
what about using
&lt;base href="&lt;?php echo site_url()?&gt;"&gt;

on the views?