-
Placing classes in php
Good day guyz, is it possible to put all class definitions in one file (class.php)?
class sample1
{
}
class sample2
{
}
-
-
-
-
include('directory/file.php');
For bigger projects, it is normal to have a "main.php" page (or whatever you want to call it), then include that page in each of your normal pages. Within main.php, include every file you need like class definitions, functions, and other information you need to define each time, like for example a login routine.
Note that if you need to include a page within another page, then the paths can change, so the easiest way to do that is this:
include(dirname(__FILE__).'/directory/file.php');
If you want help, please ask more specific questions-- does this answer everything?
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
for modularity (which is part of what classes are all about), I like to keep each class in its own file. I can load classes as needed for each page, thus loading only what I need (or use __autoload, though I prefer not).
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks