Is it good practice to separate the front-end PHP library from the back-end?
It seems, at the moment, better to share a library between the front-end and back-end.
I am curious to hear opinions about this.
Thanks!
Front-end and back-end shared or separate libraries?
Moderator: General Moderators
-
letseatfood
- Forum Newbie
- Posts: 9
- Joined: Mon Aug 02, 2010 3:50 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Front-end and back-end shared or separate libraries?
All my applications on a given server share the same library. However, in the context of one application, yes it is a good idea to share your library between different "modules". It will certainly make things a lot easier when upgrading given libraries, but it does come at the cost of potentially breaking functionality elsewhere (which is why it is important to unit test!).
-
letseatfood
- Forum Newbie
- Posts: 9
- Joined: Mon Aug 02, 2010 3:50 pm
Re: Front-end and back-end shared or separate libraries?
@John - Thanks for your response. I can see how "potentially breaking functionality" could be an issue, but with proper testing, prevented.
Two related questions I have about sharing my current library with two or more "modules" are:
Do you think I should move the [lib] directory, which I would like to share with other modules within the [root] directory into the [root]?
I appreciate any advice you might give.
Thanks!
Two related questions I have about sharing my current library with two or more "modules" are:
- Where to place the library directory within the server?
- How to refer to the files within the library? For example, absolute or relative URLs?
Code: Select all
[root]
|
|- [admin]
| |
| |- [lib] <−− Library I would like to share
| |- index.php
|
|- index.php
I appreciate any advice you might give.
Thanks!
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: Front-end and back-end shared or separate libraries?
Hello letseatfood,
Cheers
There are really two main places for the library to go. One: above the web root folder. Two: inside the web root folder (or one of it's subfolders). If you can put the library above the publicly accessible web folders, that is best. Otherwise, it doesn't matter too much where the library is.Where to place the library directory within the server?
I prefer using absolute *paths*. I do not use URLs at all for including files. URLs can be used, but if the files are on the same server, use a file path instead. It's far more secure and efficient. Either way, use an absolute path/url. I define a constant that points to my library folder. Then, anytime I need a library, it goes like this:How to refer to the files within the library? For example, absolute or relative URLs?
Code: Select all
PATH_LIBRARY . 'some_particular_library' . DIRECTORY_SEPARATOR . 'some_file.php'-
letseatfood
- Forum Newbie
- Posts: 9
- Joined: Mon Aug 02, 2010 3:50 pm
Re: Front-end and back-end shared or separate libraries?
@PHPHorizons - Thanks a lot! Is `DIRECTORY_SEPARATOR` a constant that holds a forward or backward slash?
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: Front-end and back-end shared or separate libraries?
You're welcome letseatfood,
Cheers
Absolutely. It's handy when a script might be used on Windows or Linux, since this value is tied to the operating systems own directory separator.letseatfood wrote:Is `DIRECTORY_SEPARATOR` a constant that holds a forward or backward slash?
Cheers
-
letseatfood
- Forum Newbie
- Posts: 9
- Joined: Mon Aug 02, 2010 3:50 pm
Re: Front-end and back-end shared or separate libraries?
@PHPHorizons - Thanks! I had never thought about that, what a useful tip.