hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : How to set the file paths for images, js, css files in a typical MVC Framework?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

How to set the file paths for images, js, css files in a typical MVC Framework?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 03-08-2006, 04:02 PM
grabmail grabmail is offline
Web Hosting Evangelist
 
Join Date: Dec 2005
Posts: 549

How to set the file paths for images, js, css files in a typical MVC Framework?


Eg.

Assuming, your images folder is at web root. i.e. http://localhost/images

URl is http://localhost/index.php/blog/comments

Even though you are at index.php,

images/image.jpg will not work since the / in the url trick the path info.

So how do i solve this problem?

by the way, what's the mod_rewrite rules to get rid of index.php

i want http://localhost/blog/comments

Reply With Quote


Sponsored Links
  #2  
Old 03-08-2006, 07:46 PM
JustinH JustinH is offline
Web Hosting Master
 
Join Date: Nov 2000
Posts: 3,042
I use several path constants and will the full url/path to whatever directory I use. I set it up in the config directory, and set all the paths you will be using throughout the script, ie:

PHP Code:
define ('DS'DIRECTORY_SEPARATOR);
define ('ROOT_PATH'dirname(__FILE__) . DS);
define ('BASE_URL'URL $_SERVER['SCRIPT_NAME']);
define('CONTROLLERS'ROOT_PATH 'controllers' DS);
define('MODELS'ROOT_PATH 'models' DS);
define('VIEWS'ROOT_PATH 'views' DS);
define('IMAGES'ROOT_PATH 'images' DS); 
(DIRECTORY_SEPARATOR is a pre-defined constant in PHP). Not only does this make it easier for you to code with, it makes it a quick change if you move directories.

__________________
A well-reasoned assumption is very close to fact.
- Adorno


Reply With Quote
  #3  
Old 03-08-2006, 11:51 PM
grabmail grabmail is offline
Web Hosting Evangelist
 
Join Date: Dec 2005
Posts: 549
what's the URL in define ('BASE_URL', URL . $_SERVER['SCRIPT_NAME']);

Reply With Quote
Sponsored Links
  #4  
Old 03-08-2006, 11:52 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
URL would be

define('URL','http://localhost/');

or you could swap it with the value of URL

doesn't matter.

Reply With Quote
  #5  
Old 03-09-2006, 12:20 AM
grabmail grabmail is offline
Web Hosting Evangelist
 
Join Date: Dec 2005
Posts: 549
what's BASE_URL for?

Reply With Quote
  #6  
Old 03-09-2006, 01:00 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
It's called an example.

Try using common sense!

Reply With Quote
  #7  
Old 03-09-2006, 05:23 PM
grabmail grabmail is offline
Web Hosting Evangelist
 
Join Date: Dec 2005
Posts: 549
no! i mean. why did justin set a constant BASE_URL for?

What use is it in an MVC environ?

Reply With Quote
  #8  
Old 03-09-2006, 10:51 PM
JustinH JustinH is offline
Web Hosting Master
 
Join Date: Nov 2000
Posts: 3,042
I forgot to add URL in there. I have the end user define the URL itself, and then I set it as a constant URL... the BASE_URL is for the script itself (although, my naming convention really isn't proper). The purpose behind this is modularity... if I ever add a module that requires a separate file, I already have the URL directive set.

It's not entirely needed, but useful if you ever expand the program.

__________________
A well-reasoned assumption is very close to fact.
- Adorno


Reply With Quote
  #9  
Old 03-10-2006, 01:45 AM
deuce868 deuce868 is offline
Junior Guru
 
Join Date: Jan 2003
Location: MI
Posts: 229
I do the same thing. I have constants for the Library folder, Images, External, and a base url that is prepended to all the others. That way you can move the site from the web root to an /apps/ folder and the base url get updated and auto updates the rest.

Then I can just
require(LIBRARY . 'PEAR/SMTP.php');

or

<img src="<?php print IMAGE_PATH; ?>logo.gif">

and nothing breaks.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
BitTorrent to Launch Cloud Storage Service Web Hosting News 2013-01-25 15:39:23
Court Documents Show Megaupload Helped Feds Take Down File Sharing Service NinjaVideo Web Hosting News 2012-11-21 10:53:49
Pancake.io, DropPages Let Users Host Web Site Files on DropBox Blog 2011-12-08 17:03:11
Web Host U-SYNC Launches CM4all OnlineDrive-Powered Cloud Storage Web Hosting News 2011-06-22 20:54:21
Security Firm Trustwave Launches Cloud-Based File Integrity Monitor Web Hosting News 2011-06-21 18:47:57


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?