Jump to content

Making a framework


MFHJoe

Recommended Posts

Hi,

I'm thinking about starting off a simple PHP framework using OOP which I can use in my applications.

I want the structure to be something like this:

 

- index.php (uses the framework)
- framework
   - core.php (decides which framework files to include and grabs the config)
- library
   - errors.php (the error handler)
   - database.php (the database handler)
   - forms.php (the form handler)
- config
   - defaults.php (holds the default config)
   - config.php (hold the user-defined config)

 

The thing is, I need everything to link in with each other, ie. I need to use the error class on it's own, as well as in the database handler and the form handler. All files also need to be able to use the config.

 

Early tests show that I can't do this. Any ideas?

Link to comment
Share on other sites

you might want to include all of the related files into one file, so it might be a little to manage...I don't know if you should do this in framework, but I would think it would be ok.

 

For example:

 

library.php

<?php
include "errors.php";
include "database.php";
include "forms.php";
?>

 

so now you can just call library.php if you need any one of those 3 pages.

Link to comment
Share on other sites

  • 4 weeks later...

you could also use the __autoload function of PHP.  This would be more ideal becuase if you start to have 5, 10, 15, so on class files, loading them all everytime when you just need one would slow the script down becuase the with above idea, it would have to load everything instead of just the 1 file you need.  also this way you will not have to worry about including those class file since they will be included automatically.

Link to comment
Share on other sites

  • 2 weeks later...

autoload is bad for performance so I would not use it for loading the framework as frameworks should try to be as efficient as possible. But that said autoload should be fine for loading the app built with the framework.

 

Also spl_autoload_register is better for framework design in my opinion to __autoload as you can do something like spl_autoload_register(array($this, 'autoload'));

Link to comment
Share on other sites

Well,

  I would recommend you read about autoloading of classes from php.net comments in classes and objects section there are a lot of good scripts to help you do the same. You could also just make up the config class that holds up the config data and use it.  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.