paul1981 Posted August 8, 2006 Share Posted August 8, 2006 Hi all I have hit a wall and am looking for a new idea if anyone has one.Here is what i am doing.I have a function that displays a box witch the text sits in.everything is fine with that and it works great. how ever i find i keep having to create more and more of the same function but with differant paths for the images file.images/image1.gif../images/image..gifand so on depending on were the page is i am linking from.I just wondered if anyone has any ideas on a better way to manage the function.so i could just have the 1 set of functions for every page no matter what folder they were in.Any ideas welcome.Paul1981 Quote Link to comment Share on other sites More sharing options...
glenelkins Posted August 8, 2006 Share Posted August 8, 2006 Can you please post the code for the function, and try to explain the situation a little clearer. I would mainly suggest puttin the function in a class and include the class only in every page, but im not totally sure what your asking. Or you could set a variable in the function to take the path of the file you want it to look at. Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 8, 2006 Share Posted August 8, 2006 Use objects. And only change the paramaters/values. One function/class accross the board. (In other words, take an object oriented approach) Quote Link to comment Share on other sites More sharing options...
glenelkins Posted August 8, 2006 Share Posted August 8, 2006 Exactly! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 you could define the absolute path instead.so if the image was in www.ursite.com/global/images/image1.gif you could just define the path as:"/global/images/image1.gif" Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 OOP is great but in many cases its a bit overkill...Unless you have a massive site i see few reasons to use it - especially in this case when its only a file path that needs to be defined. Quote Link to comment Share on other sites More sharing options...
Caesar Posted August 8, 2006 Share Posted August 8, 2006 [quote author=ToonMariner link=topic=103462.msg411936#msg411936 date=1155064780]OOP is great but in many cases its a bit overkill...Unless you have a massive site i see few reasons to use it - especially in this case when its only a file path that needs to be defined.[/quote]Lies! :-P Quote Link to comment Share on other sites More sharing options...
paul1981 Posted August 8, 2006 Author Share Posted August 8, 2006 Firstly thanks for you fast replys.[code]<?phpfunction opentable(){echo"<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"> <tr><td width=\"15\"><img src=\"image/left_side.gif\" width=\"15\" height=\"22\"></td><td width=\"100%\" background=\"images/middle.gif\"></td><td width=\"15\"><img src=\"images/right_side.gif\" width=\"15\" height=\"22\"></td></tr><tr><td>";}?>[/code]Right that the function for opening the table as i said in the last post it works fine.I will try to explain in more detail this time.Ok main folder is say index.php and also in that folder is the images folder.you call the function on the index and it opens the table fine.now i create a folder in side the main folder called say folder1 and have lets say another index.php in there. Now when i call the function its still looking at images/left_side.gif as the path to the file when in fact the path should be.../images/left_side.gifSo to solve this i have 2 functionsopentable and opentable1 Its working find but i am finding that every time i add a new folder i need to add a new functioni was wondering as i said above if there is a better way to manage the function and just have 1 function for all.What about an array? been playing and have it sort of working if i echo the correct number $image[2] say of 2 is ../images/left_side.gif. But never used arrays before so not that good with them.Thanks again for any ideas Paul1981 Quote Link to comment Share on other sites More sharing options...
paul1981 Posted August 8, 2006 Author Share Posted August 8, 2006 Caesar could you explain a bit more about the below? Never heard of that.Use objects. And only change the paramaters/values. One function/class accross the board. (In other words, take an object oriented approach)Paul1981 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 Ok Don't believe me.... Quote Link to comment Share on other sites More sharing options...
paul1981 Posted August 8, 2006 Author Share Posted August 8, 2006 Sorry ToonMariner I do believe you mate. Just wondered what ideas the others had also.Paul1981 Quote Link to comment Share on other sites More sharing options...
corbin Posted August 8, 2006 Share Posted August 8, 2006 [code=php:0]<?phpfunction opentable(){echo"<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"> <tr><td width=\"15\"><img src=\"/image/left_side.gif\" width=\"15\" height=\"22\"></td><td width=\"100%\" background=\"/images/middle.gif\"></td><td width=\"15\"><img src=\"/images/right_side.gif\" width=\"15\" height=\"22\"></td></tr><tr><td>";}?>[/code]Should do it... It will look in /images/ no matter where its called from instead of current directory/images... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.