Jump to content

MicroMVC - A tiny PHP5 Framework


Xeoncross

Recommended Posts

I just finished a Small Framework (~90kb) based off of the CodeIgniter/Zend Style of handling things.

 

I would love it if some people would test it. It doesn't require any kind of install - just a path variable change in the .htaccess (if you use it in a subfolder)

 

http://code.google.com/p/micromvc-php/

 

I built this to have a base to compare the speed of other frameworks like CodeIgniter, Zend, Solar, and CakePHP.

 

It offers Model, Library, Controller, Function, and View management. Plus other features like URI Routing, hooks/plugins, file uploads, database abstraction, captcha creation, and more! If you are new the Model/View/Controller world of OOP - then this system is for you. Every line is documented and it is as simple of a system to tear-apart as you can get.

 

MicroMVC is not a replacement for a full MCV framework. Do not plan on building the next Facebook with it! However, It is built for several reasons.

 

    * Teach How MVC Works with a simple-to-understand code structure.

    * Provide a base speed for comparing frameworks

    * Run small scripts and systems (like blogs) that need MVC without a lot of overhead.

    * To power parts of Code 2 Design that did not need a full CMS.

 

MicroMVC is licensed under the GPL v3 so you can use it for any personal or corporate projects free of charge.

 

 

I would love feedback on this!  ;D

 

 

 

Link to comment
Share on other sites

MicroMVC is licensed under the GPL v3 so you can use it for any personal or corporate projects free of charge.

 

This is only true if it is a open source project, any commercial product and you would still be forced to release under GPL which makes it impossible to sell the product itself(you could only sell support).

 

Now about the Framework:

 

NOTE: these comment on how my MVC framework works and what i am trying to do with it so some of my comment may be something you are not trying to do but if they are i would like to know why just to kinda pick your brain.

 

1. This is all based off a quick 10-15 mins looking at the code so correct me if i am wrong

 

2. The controller setup look ok to me but have not gone deep into it.

 

3. The view setup seem like all view are going to be in 1 folder which i guess it very for very basic site(which it what you are going for) be even very basic site can have views with the same name.

 

4 .The model portion does not seem to exist.  In the model folder there is a sqlite abstraction layer(i assume from the name) but a database abstraction layer in a model portion of a MVC (or ORM system).  Do you actually want to have a model/ORM system like Zend/Symfony or not like code igniter?

 

5. Also there does not seems to be any type of autoload functionality.  Having to manually require file in a MVC framework is not normal.

 

Now number 3 and 5 might be done that way to speed up the framework as autoload functionality can add time so i would be interested in that is in fact the reason those are done that way.

 

I think the framework is over not bad and the speed is good.  Basic testing with just loading a view, your framework does 200 - 220 RPS, my framework does 120-140 RPS, and from what i remember Zend did like 50-70 RPS on my system(all test done with ab -n100 -c100).

 

I think the framework is not a bad intro to MVC but i think a website/web application can quickly out grow it.

Link to comment
Share on other sites

you would still be forced to release under GPL which makes it impossible to sell the product itself(you could only sell support).

Precisely   ;)

I didn't build if for someone to turn around an sell it to people - but I did build it so anyone that wanted to could use it.

 

 

3. The view setup seem like all view are going to be in 1 folder which i guess it very for very basic site(which it what you are going for) be even very basic site can have views with the same name.

 

No, the view supports (and should use!) subfolders for each controllers views.

 

4 .The model portion does not seem to exist.  In the model folder there is a sqlite abstraction layer(i assume from the name) but a database abstraction layer in a model portion of a MVC (or ORM system).  Do you actually want to have a model/ORM system like Zend/Symfony or not like code igniter?

 

Yes, in my haste I forgot to include the PDO ORM I built - so I need to get that in there - in the mean time people can download it and just place it in the Models folder. The only models in there are one to connect with the Akismet service and a sample SQLite driver.

 

5. Also there does not seems to be any type of autoload functionality.  Having to manually require file in a MVC framework is not normal.

 

Your right - loading files at all is a bad thing. This system does support autoloading however - just not like Zend does. If you want a model, function, view, config, library, or anything else you use the load() Function to make sure you don't include some things twice.

 

But placing require() or include() in your code is not recommended!

 

 

I think the framework is over not bad and the speed is good.  Basic testing with just loading a view, your framework does 200 - 220 RPS, my framework does 120-140 RPS, and from what i remember Zend did like 50-70 RPS on my system(all test done with ab -n100 -c100).

Yes, aside from missing all the cool libraries that other MVC systems have (email, XML, ACL, etc..) my system's core is way, way, way smaller and yet still allows the same style as other systems. I still need to make "custom" routing configs though - so you can override the url path.

 

 

I really appreciate you taking the time to look into this system. Thanks again!

 

 

 

Link to comment
Share on other sites

5. Also there does not seems to be any type of autoload functionality.  Having to manually require file in a MVC framework is not normal.

 

Your right - loading files at all is a bad thing. This system does support autoloading however - just not like Zend does. If you want a model, function, view, config, library, or anything else you use the load() Function to make sure you don't include some things twice.

 

But placing require() or include() in your code is not recommended!

 

I would agree but i don't know of any way around it when using a ORM type system.  if you are going to manually require files, you have to use require_once since you can't include the same file.  My framework tries to make things like that automatically and you don't have to worry about it.  The way i currently have it is that there is a configuration of directories and the code recursively searches those directories for any php file with .class.php and load that data into a XML file(both the file name and the directory) and this only happens if the xml file does not exist or a class you are trying to load does not exist in the xml file.  If the xml file is there then the data is read into an array and the __autoload uses that to load files.  This allow for the most flexible directory structure that i use(i hate the way zend forces you to name your files and the directory structure you much follow).

Link to comment
Share on other sites

 

The way this system works is - IF you need a library, model, view, library, or config then you load() it in the constructor of the controller - or somewhere else in the controller. There is no need to autoload a bunch of classes until they are actually needed. However, if you know a class/function will be needed for every controller then you can place it in the "includes" directory and I will be loaded at startup.

 

by using the $this->load() function you can be sure that the same model/library/function file is never loaded twice. However, you can load config files as many times as you want.

 

 

 

 

Link to comment
Share on other sites

The way this system works is - IF you need a library, model, view, library, or config then you load() it in the constructor of the controller - or somewhere else in the controller. There is no need to autoload a bunch of classes until they are actually needed. However, if you know a class/function will be needed for every controller then you can place it in the "includes" directory and I will be loaded at startup.

 

I do agree with this, nothing should be loaded unless you are going to use it.

 

The way i currently have it is that there is a configuration of directories and the code recursively searches those directories for any php file with .class.php and load that data into a XML file(both the file name and the directory) and this only happens if the xml file does not exist or a class you are trying to load does not exist in the xml file.  If the xml file is there then the data is read into an array and the __autoload uses that to load files.  This allow for the most flexible directory structure that i use(i hate the way zend forces you to name your files and the directory structure you much follow).

 

What I am doing in my framework is just have an array with all the stuff paths stuff I am going to use and when a class get's called I just search the array. I just have the basic path written in the array, not the full path, that get's "calculated" when the framework loads.

I tried xml and scanning the dirs but the xml takes loads of time to load (checked this with Xdebug) and also the scanning of dirs is not a simple task in terms of performance

Link to comment
Share on other sites

First, let me commend you for relasing your TinyMVC to the the wolves. Releasing your code, knowing that developers like to scrutinize, is a great achievement!

 

Since there isn't an API documentation I was left looking at the twitter implementation. I'm impressed, there's no doubt about the amount of time and effort you put in to the code and I would think it would serve as a great addition to the portfolio/resume.

 

Some questions, comments, etc.

 

1. Can you pass parameters to the methods in your Controller? I noticed in some places in controllers/twitter.php I was thinking.. 'this would benefit from having a parameter or two' (check the user_timeline() function.

 

2. I assume setting $this->data['content'] is what actually gets the page displayed. Do you think having a method in the core.php called something like 'render' would help? I think it would help your syntactic sugar and make things a bit more readable.

 

3. What does the hooks() function do?

 

 

 

My only gripe was I had to convert all of your files to UNIX format. Saving them in DOS (\r\n) makes it hard to read on my pretty terminals ;)

 

keeb@deviL:~/micromvc-php-read-only$ perl -pi -e 's/\r\n/\n/;' `find . -name "*.php"`

 

 

 

 

 

Link to comment
Share on other sites

What I am doing in my framework is just have an array with all the stuff paths stuff I am going to use and when a class get's called I just search the array. I just have the basic path written in the array, not the full path, that get's "calculated" when the framework loads.

 

acs: what do you mean by "calculated"?

 

The scanning of directories only happens once in a while.  It happen the first time you run any page and then again if you are trying to load a new file that is not in the cached xml file, once the directories are scanned, it just load from the xml file.

 

The reason i do file loading that way i do is to remove that configuration part that would have to be done in your framework(from the sound of it).  for example at work where i am using the first version of my framework, we have over 70 model classes based on our database(that has like 140+ tables).  We also have 3 websites that run from the same database which mean when we add a new model class we would need to remember to add the configuration for the class in each of the 3 site configuration file.

 

Also about the xml "takes loads of time to load", i use simplexml_load_file which from cacheout grind from xdebug does not even register any time(each time just has a - under is for simplexml_load_file).  Now that was with a 3K file with 23 files configured in the xml.  I tried with with 873 files configured into the xml(which is 94K) and that took 0.3 ms to load(with the entire thing taking 2.3ms to load just a simple static view file).  0.3 does not seem that slow with 873 files configured since it would be very hard to have that many classes in the configuration file anyways.

 

Once php 5.3 beta works with apache as a module(since i can't get it to work as CGI), then i would be able to us XDebug(right now using php 6.0 because that works as module and the new version of my framework requires the static functionality of classes in php 5.3) to test the speed of my framework as try to see if there is a faster way to load classes automatically without requiring extra configuration.

Link to comment
Share on other sites

Well I was not only using simpleXML, but also a function that would turn the xml into an array for easier use. I guess I will retry to see if it is faster to either recalculate everything at start up or save it on a xml file and then load it. And by calculate I just mean stuff like getting the path's to the file via __FILE__ or getting the address of the server etc etc

 

But nice framework, already gave me some stuff on the .htaccess file and nice way to check for ajax didn't even know you could do that :D

Link to comment
Share on other sites

Or at least don't mix it with php5 syntax. Keep your code consistent.

One thing I don't get is why are you trying to have one copy of the framework serve N sites.

I think the database.php file and the server.php file could all be in the config.php just for the sake of organization.

And I am not understanding this hooks thing. Seems to me like you are just including a file on an action nothing else. When I think of hooks I think of events, like when the class loads or when a an action is called (not the hooks actions itself but the event of an action). Maybe I just getting confused with the wording :P 

Link to comment
Share on other sites

First, let me commend you for relasing your TinyMVC to the the wolves. Releasing your code, knowing that developers like to scrutinize, is a great achievement!

 

Yes, I often find that developers are so zealous you often fear actually giving our code out!  ;D

 

 

Since there isn't an API documentation I was left looking at the twitter implementation. I'm impressed, there's no doubt about the amount of time and effort you put in to the code and I would think it would serve as a great addition to the portfolio/resume.

 

I did spend some time building it - but it was a great learning experience. I wanted to offer the best parts of a MVC framework without extra junk. I looked at how other systems handled things and improved them ;)

 

 

1. Can you pass parameters to the methods in your Controller? I noticed in some places in controllers/twitter.php I was thinking.. 'this would benefit from having a parameter or two' (check the user_timeline() function.

 

Yes, if you were to do site.com/welcome/example/hello world then the string "hello world" would be passed to welcome::example().

 

 

2. I assume setting $this->data['content'] is what actually gets the page displayed. Do you think having a method in the core.php called something like 'render' would help? I think it would help your syntactic sugar and make things a bit more readable.

 

Actually, there is a "render()" function which places the controller::$data inside the "layout.php" file. However, if you are doing an ajax request or something you can just load a view and die();

 

function example($var='') {
$this->view('welcome/example', array('var' => $var), null);
die('done');
}

 

You can also change the layout file to be loaded by setting the core::$layout variable in your controller. Ajax requests are set to "ajax.php" for example.

 

 

3. What does the hooks() function do?

 

the welcome->hooks() function shows how hooks work in the system. It loads the example hook_test.php and my_second_hook.php files and runs the objects and methods.

 

 

My only gripe was I had to convert all of your files to UNIX format. Saving them in DOS (\r\n) makes it hard to read on my pretty terminals ;)

 

Thanks I forgot about that as I am still stuck in the M$ world...

 

Link to comment
Share on other sites

 

And about the PHP4-5 stuff - I just haven't fixed all the lang styles yet. I started building it to work with PHP4 but then dropped it as the only people that would use this system should already be PHP5  ::)

 

Also, I will have a video about the system up tomorrow  ;D

Link to comment
Share on other sites

Nice.. You don't comment on code but when the topic is a about a framework you comment about the layout of the author's website... really nice

I am also on a 22' monitor and I have no problem with it. The image is nice.

Link to comment
Share on other sites

you site it nice and i do like the header image, looks very cool, but i d agree it is a bit too big for my taste.

 

Another thing i will comment on about the code is that it seems, in at least the database class, you are not consisted in you name conventions(i assume the writer since you say you own codexplorer.com).  Most of your code seems to be all lower case with underscores(which btw i prefer and don't see many people coding that way), in the cxpdo class are are methods named: getQuoteIdentifierSymbol and quoteIdentifier.  Just something you might want to take a look at.

 

Keep MicroMVC in the back of your mind - because it will

change the way people use websites.  ;)

 

I am not sure about that at least at the current state of the framework.

 

Another thing i will say is that I would never not consider a PHP Framework because of the size of the system(unless it was retardly large) because the file are not sent over a network to be parsed, they are directly on the server to parse and parsing file is quite fast.  Now if it was javascript, that would be a different case since you first have to send the file to the client and then it gets parsed.

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.