Referencing Image with Front Controller Pattern

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Referencing Image with Front Controller Pattern

Post by jimthunderbird »

Hi All,
I'm having problem with referencing image,css,javascript with this front controller pattern.

First, I'm working on a structure that will allow the design team and programming team work seperately, it goes like this:

Code: Select all

www/index.php
            /template
                           /cache
                           /designer_jim/ 
                                                /css --- store all css from designer jim
                                                /image --- store all images from designer jim
                                                           /logo.jpg
                                                /script--- store all javascripts from designer jim
                                                /common --- store all common header,footer,leftbar,rightbar... from designer jim
                                                /sub --- store all other templates with multi-level categories
                                                       /cat_1
                                                                 /cat_2
                                                                           /cat_3
                                                                                     /sometemplate.tpl

                           /designer_tom/
                                                /css
                                                /image
                                               /script
                                               /common
                                              ...

            /logic --- all application logics stored here

The designer likes dreamweaver very much and he likes to see the refrencing images up there when testing on dreamweaver. So in the sometemplate.tpl he would reference the logo.jpg in the image folder using ../../../../image/logo.jpg, this can be done in DW really easy with relative path referencing. He is happy to see the image when having a test with DW.
Now I'm not happy! Since I do include_once("template/designer_jim/sub/cat_1/cat_2/cat_3/sometemplate.tpl") in the index.php as a controller, all images references screw up!
I post this problem in another thread here and thinking of copying that tpl file and use str_replace to replace those ../../ things in the image path with my own path,then save the processed template in the cache folder, but this involved openning and closing a file.

Doesn anyone know a better solution than this? I'm afraid the file opening and closing will slow down the speed. Can I avoid that while still keep the image referencing correct? This problem also occured when referencing css and javascript.



Hope I state the problem clear and hope to hear from you all.

With my best,
Jim
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Emulate the directory structure using mod_rewrite, which still directs the requests to your front controller but makes the client "think" that he's dealing with folders.
Post Reply