Updated Jan 16th, 2013
Mvc

MVC frameworks

Fuelphp

Laravel - Next big thing

CIBonfire - dead

Slim

Silex

Tiny MVC

http://net.tutsplus.com/tutorials/php/create-your-first-tiny-mvc-boilerplate-with-php/

index.php
    require 'load.php'
    require 'model.php'
    require 'controller.php'
    new Controller();
application/
/controller.php
    class Controller {
        public $load;
        public $model;
        function __construct(){
            $this->load = new Load();
            $this->model = new Model();

            // do routing
            $this->home();
        }

        function home() {
            $data = $this->model->user_info();
            $this->load('view/someview.php', $data);
        }
    }
/model.php
    class Model {
        public function user_info() {
            return $results_array;
        }
    }
/load.php
    class Load {
        function view($file_name, $data) {
            if (is_array($data) extract($data);
            include 'views/'.$file_name;
        }
    }
views/
/someview.php
    html goes here

Routing

$parts = explode('/',$_SERVER['REQUEST_URI']);


$this->_controller = ($c = array_shift($parts))? $c: 'index';
$this->_method = ($c = array_shift($parts))? $c: 'index';

$this->_args = (isset($parts[0])) ? $parts : array();

modular design: http://www.slideshare.net/nzakas/scalable-javascript-application-architecture

Main considerations: Total unification. I want a framework that works smoothly with a javascript framework.

I want to spend less time creating things that have already been created, but at the same time I don't want to use shit.

Try

  • kohana (hmvc)
  • fuelphp
  • lithium
  • Yii

Social Frameworks

buddypress elgg

Read

Patterns of Enterprise Application Architecture (I strongly urge you to read Martin Fowler’s book if you want to become a good OO programmer and easily understand the likes of Zend Framework).

Frameworks

I've used...

  • Ruby on Rails (Slow on shared server, otherwise perfect!)
  • CakePHP (Feels kind of frumpy, but does allow nested table relationships)
  • Codeigniter (Very minimal, requires you to specify most of the models interactions with the table)

My Progression

  1. Started with Codeigniter (Easy to understand what it was doing)
  2. I needed more robust database interaction so I moved to cakephp (Handles nested tables well)
  3. And then I had the opportunity to use Rails.. which majorly improved my skills in all these frameworks.
  4. From here, I tried to build my own. Which is interesting and not too hard! But ultimately determined, it's not productive to use your own framework. Do it for education, not for a project.
  5. Now, I understand models and database interactions much better after using rails, with the concept of creating thin controllers and fat models. Moved back to Codeigniter.
  6. Now I use Codeigniter for most things. I've eliminated databases and use a YAML / MARKDOWN technique that suits me quite well. Happiness.
  7. I am considering using Symfony or CakePHP for larger projects again. I need unit testing, a proper database model, and Restfulness. I don't want to dirty up my code with a lot of poor fitting plugins.. I want a larger framework that has A WAY.

building an mvc

http://php.net/manual/en/function.method-exists.php http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

Unit Testing

  • While unit testing appears to be cool.. on anything but a large project it's probably a waste of everyone's time.
  • Changed my mind on this.. If something goes wrong, a php version changes, or something in the configuration of the app, or you just refactored the code to be better, something else could break. And if you don't have unit testing, now you get to go through all your code and spend a very frustrating time debugging.
  • Use it wisely! For interactions with an api or db it is impotant.