tehprofessor Posted September 2, 2011 Share Posted September 2, 2011 Howdy Y'all, I'm writing a php MVC framework to learn php, I've been at it about a week, and I was wondering if I could get some feedback. Since I'm new to PHP I'm mostly looking for tips on coding best practices, MVC design tips, or if there are any big "WTFs?" in my code where I've obviously missed the point. I'm hoping when it's finished to document it thoroughly to help others trying to learn. About the framework/purpose: My goal is mainly to write/stitch-together a router, dispatcher, security/sanitization, controller, and logger. For the models I'm extending phpActiveRecord and for the views, I'm using smarty templates (writing a template engine and abstracting SQL didn't sound appealing, plus I feel like those should both be pretty modular). I choose phpActiveRecord simply because I typically use rails, and it was the most familiar ORM I could find. https://github.com/tehprofessor/arrgh.framework Credits for code/tutorials I used in the process at the bottom of the github page. It's licensed under MIT (where applicable) so if you want to use it for something, go ahead! I've documented a fair bit, so hopefully it's not impossible to figure out what I've done. I'm currently finishing up rewriting the router and dispatcher, so it doesn't do much but parse parts of the url. Cheers. Edit: I'm sorry if I posted this in the wrong forum. I did try to find the right place, an this seemed the most appropriate. Link to comment https://forums.phpfreaks.com/topic/246309-feedbacksharing-custom-mvc-framework-for-learning-not-production/ Share on other sites More sharing options...
trq Posted September 3, 2011 Share Posted September 3, 2011 A few things. Firstly, I didn't actually download any code, just hade a quick look through it on github. I don't really see where the framework itself resides. I managed to track down a file in vendor/framework/framework.php which appears to be some sort of Application object (class named Arrgh), but this object depends on Logger and Route objects that I am not able to locate anywhere. It's also very odd to have a class within a file of a different name. The general best practice is to name your files so they map 1-1 with there contents. This makes autoloading a breeze. It also seems odd to have this file (if this is indeed part of your framework) within a directory called vendor. Vendor directories are generally for third party code. This brings me to my next point. Smarty? I'm not sure its a great idea to dump that kind of dependency on anyone. Personally i think template engines are well overrated in PHP, but smarty in particular is a pretty big dependency to have to pull. Link to comment https://forums.phpfreaks.com/topic/246309-feedbacksharing-custom-mvc-framework-for-learning-not-production/#findComment-1264950 Share on other sites More sharing options...
tehprofessor Posted September 3, 2011 Author Share Posted September 3, 2011 Thanks for the info! Also sorry about posting in the wrong place, thanks for the assistance. I suppose to help others, most of the framework's core files are located in /vendor/framework/config && /vendor/app/ The files are loaded starting from application.php inside the public folder. Link to comment https://forums.phpfreaks.com/topic/246309-feedbacksharing-custom-mvc-framework-for-learning-not-production/#findComment-1264954 Share on other sites More sharing options...
trq Posted September 3, 2011 Share Posted September 3, 2011 Looking at it a little further, there seem to be a few funny design decisions going on. Your Route object extends Arrgh, yet also depends on (and uses) Arrgh. Same goes for the View which extends the Controller yet the Controller also depends on (and uses) a Controller. A View object isn't the same type as a Controller, therefore a View really shouldn't extend a Controller. I thought Ruby devs where all about OOP? Link to comment https://forums.phpfreaks.com/topic/246309-feedbacksharing-custom-mvc-framework-for-learning-not-production/#findComment-1264979 Share on other sites More sharing options...
tehprofessor Posted September 3, 2011 Author Share Posted September 3, 2011 Yeah, I had a different setup I didn't think was working very well when I was starting out ...and I was definitely fuzzy about how inheritance worked (I was initially quite opposed to a lack of multiple class inheritance, but it actually works out rather well and forces some good practices). I got to plotting away on redoing the router and forgot to clean 'em up. Should be better. Also I think you're right about Smarty, but how it [my framework] handles templates it's pretty easy to change as the view logic is independent (I fixed it so it's not inheriting the controller class). Thanks a bunch for the feedback so far, thorpe. Link to comment https://forums.phpfreaks.com/topic/246309-feedbacksharing-custom-mvc-framework-for-learning-not-production/#findComment-1265018 Share on other sites More sharing options...
Recommended Posts