2. Who are You?
• Vance Lucas
• http://vancelucas.com
• @vlucas (for heckling)
• PHP since 1999 (PHP3)
• Brightbit
• http://brightbit.com
• Design, Development & Consulting for
web apps, mobile apps and APIs
4. MVC Frameworks
• I’ve created LOTS of MVC frameworks.
• They all sucked.
• Except maybe one.
• Alloy Framework
• Released Feb. 2011
• But it’s dead to me now…
7. “The fool hath said in
his heart, There is no
better architectural
pattern than MVC”
* may not be exact quote
8. “I don't like MVC because that's
not how the web works.
Symfony2 is an HTTP framework;
it is a Request/Response
framework. That's the big deal.”
Fabien Potencier
http://fabien.potencier.org/article/49/what-is-symfony2
October 25, 2011
9. Philosophy
• Do more with less (code)
• Low cognitive overhead/complexity
• Embrace HTTP
• Leverage raw PHP without introducing too
many “framework concepts”
• Only PHP knowledge should be enough
• Shouldn’t have to “fight the framework”
• “Micro” != No Structure
13. Main Concepts
• Micro-framework
•
URL Routing, Request, Response, Templates
• Built around HTTP and defined URIs
• Parses one URI segment at a time
• Declarative, functional-style nested routing
• Leverages closures for structure and scope
• Less repetitive code, cleaner routes
14. Guiding Rules
• Only one path segment at a time, and only
Closures can be used
• Response must be explicitly returned
• Path must be fully consumed (or error)
• Handlers for different behavior:
• Path, Param, Method, Format
• Method and format handlers only run
when path has been fully consumed
20. Typical MVC Controller
class BlogController extends BaseController {!
public function getView($slug)!
{!
// Get this blog post data!
$post = $this->post->where('slug', '=', $slug)->first();!
!
!
// Check if the blog post exists!
if (is_null($post)) {!
return App::abort(404);!
}!
// Show the page!
return View::make('site/blog/view_post', compact('post', 'comments',
'canComment'));!
}!
}
37. Events
• Global: ‘before’, and ‘after’
• Dynamic
• [http_status_code] - 404, 500, etc.
• [response_format] - json, html, etc.
• [exception_class] - exception class name
like “InvalidArgumentException” or just
“Exception” to catch all exceptions