Julius Posted February 6, 2011 Share Posted February 6, 2011 Hi, I'm trying to write my own php mvc framework, but I don't know where to start. I have been using codeigniter for a while, then i thought i shouldn't use it, because I'm not getting smarter when most of the code is written for me. So, writting my own framework would be a great practice to learn oop, i guess. I need: url routing, the would work like codeigniter's (http://website.com/controller/method/some/other/params) and calling some function for rendering layout files similar to codeigniter's ($this -> load -> view ( 'file.php' ); and not like this: $header = new Template ( 'header.php' ); then some coding with header, and same with content.php and footer.php). Can anyone please help me? Where to start? sorry for bad English Quote Link to comment Share on other sites More sharing options...
phprocker Posted February 6, 2011 Share Posted February 6, 2011 This http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/ is a good read on the topic. Quote Link to comment Share on other sites More sharing options...
lastkarrde Posted February 7, 2011 Share Posted February 7, 2011 I have written a tutorial on writing a regular expression based URL router in PHP from scratched. If your wanting to implement routing Code Igniter style, then take a look at $_SERVER['PATH_INFO'] variable on every request. You can split the URI up with explode to get all the useful segments. Quote Link to comment Share on other sites More sharing options...
Zyx Posted February 7, 2011 Share Posted February 7, 2011 The code in the tutorial does not show any MVC. It's just a piece of code, where some parts were given the names of "model", "view" and "controller" without any noticeable sense and understanding what they actually mean. Remember that naming something "observer" and "observable" does not give us the Observer pattern, if we do not implement the correct interactions between them. The same is with MVC. Most of the current PHP frameworks (and Ruby on Rails that started the game) do not actually implement MVC, but one of its many derivatives, i.e. Model-View-Presenter with Passive View. I was working with MVC for a while, and believe me (or look for the original pattern definitions and check it yourself) - this is a completely different world from what we see. In addition, if you want to learn OOP, I would throw away the outdated CodeIgniter code. I even wonder why people are still using this framework, if there are plenty of much better alternatives. Take a look at Symfony 2, which aims to set a completely new quality among the frameworks: https://github.com/symfony/symfony . You can also look at my experimental framework, where I make MVC experiments: https://github.com/zyxist/Trinity . First of all, try to understand the concepts behind them, and their structure. Writing a framework is not easy, at least if you want it to be usable . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.