Jump to content

Designing a Framework/Library


LemonInflux

Recommended Posts

Hello. I've been looking to design a framework (something like Zend's Framework). It will be modular, and each module will have its own directory. But I would like to clear up a few things first:

 

I have my pattern. It's going to be MVC. So here's how it will run:

 

Model -- The core API, and any of the framework modules the user wishes to use. Doesn't do anything itself, but is used for everything. Modules will be in a structure like so:    /module_name/module.php  (module.php will always be called this).

View -- View files. Basically templates, with some PHP(/smarty maybe?) functionality for things like if(value == 1) { do this } else { this }. Controlled by the controller.

Controller -- Not a huge amount of code, because most of it is from the model. Uses the model to control the view.

 

So here are my questions:

 

Model

I think this is a fairly simple task, because it's just writing lots of functions really. However, as my library expands, it will become less practical to include all modules (which will all be children of a parent model/module class). So I will need some sort of identifier for each module, and a function like includeModule(). Is the best way to do this just do have includeModule($value) look for a module.php file in library/$value/? Or is there a better way of doing this (maybe a setName() function within the module.php file? If so, how would you collect this without having to run the class?)

 

View

I think I'm ok on this, but would using something like Smarty be better than just standard php foreach(), if(), else() and for() functions? I'm moving towards standard php, for the sake of simplicity, but if there's a good reason why not to, I'll go for a proper engine.

 

Controller

Back to the model issue on this one really. If I'm creating instances of classes, should I store them in the controller, or make a separate class for holding module instances? Should I have an identifier for the controller, or just include it by path name?

 

Sorry if I've rambled a bit and it's horribly unclear. If something doesn't make sense, please say and I'll try to explain it a bit better :P

 

Thanks in advance

Link to comment
Share on other sites

Well i will let you know how i have design my framework from a high level point of view.

 

I am also doing MVC as it is pretty much the standard for any web based framework.  Now this is my take on each part:

 

Controller: The controller is the simplest part of the MVC(IMO).  All the controller does is calls model and their methods and then formats that data to send it to the view file.

 

View: The view is also just a simple as the controller as all it does is take the data that the controller passed to it and then displays is.  I think it i s important to have a template system, which ever you choose, but you should also allow the user to use pure php in there template file if they wish(but this is my personal opinion).

 

Model: The model is the hardest and most time consuming piece of the puzzle for the end user and the framework developer(my framework is about 200K of code and about 110K deals direct with models).  This is where all of the meat of the website/application is going to be.

 

a couple of other things to mention before i go into the flow of my framework are the helper classes i have.  I have a url helper class which basically parses the url for the controller and controller method that the page is trying to call along with any parameters it is try to pass and anything inside the query strong.

 

I also have a custom database class.  is uses the PDO object for its connection so that is show work for almost any database the the PDO supports(but only have tested mysql).

 

I also have a framework class that basically starts the whole thing and load up common object(like url_helper, database, configuration, etc...)

 

I also have a configuration class to hold all configurations that the framework needs like the database connection stuff and what not.

 

I also have a model_filter class that builds form elements(or a complete form depending on how you use it) that will be able to filter for model record based on the model configuration.

 

I have a error class the provide a easy way to throw exceptions(which i have also create custom exception classes too) and can be extended to also do other things like database errors and what not.

 

I have a code generator class that produces model files based on database structure.

 

I have a benchmark class to provide a way to pin point script slowness.

 

Now the flow of my framework is this:  First it loads the framework starting class and this then calls the start method(this is located in the index.php).  This function pulls that controller name, controller method, and the parameters that need to be pass to the method(which is all done when the url_helper class is created) and that calls the controller method.  Now the controller will do whatever logic that needs to be done and then pass the format data to the template and which the controller you are able to load multiple view at one time.  This goes through a middle man the that parses the data that it is passed to which every method is need(whether it is using a the template engine or pure php for the view files). the view then displays the page.

 

Like i said the model functionality is going to be a large piece because in my base model class i have functionality to build forms, build form elements, resolve an id by a field(so if i do status_model::resolve_id('title', 'active') that will return me 1 this way i can use string instead of zids for stuff like statuses and types which makes programming a lot easier), generate queries by passing arrays, convert to xml, convert to array, convert to JSON, sort, automatically file upload for file input types, and so on.

 

I hope this helps a little.

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.