Streamlining Your
Applications with Web
    Frameworks
  Kings of Code ~ May 27th, 2008
What is a Web
              Framework?

• “...software framework that is designed to
  support the development of dynamic
...
What is a Web
         Framework?

• A set of tools and a way to organize them
• NOT an application
• An abstract base fro...
What is a Web
         Framework?

• Provide libraries for common tasks
• Provide structure and convention for your
  appl...
Continuum of Structure

CakePHP   CodeIgniter   Zend Framework

  More                         Less
Why Use a Framework?
• Lets you focus on what’s important
• The hard problems have already been
  solved by people smarter...
Why Cake?
• For a lot of people and a lot of reasons,
  Rails = FAIL
 • Difficult and expensive to deploy
 • Ahem! scaling....
Why Cake?
• “Oh Rasmus, why do you engage in this
  ‘virtual crap-flinging’? Can’t you lead by
  example like David Heineme...
Why Cake?
• Other PHP frameworks
 • Zend Framework
 • Symfony
 • PHP on Trax
 • CodeIgniter
An MVC Quickie
 Dispatcher    The Dispatcher requests the
              appropriate Controller/action,
                whi...
An MVC Quickie

• Primary: separation between Controller
  and View, to partition business logic and
  presentation
• Seco...
An MVC Quickie
    A simple example
/* models/post.php */

class Post extends AppModel { }

/* controllers/posts_controlle...
<div class=quot;posts indexquot;>
<h2>Posts</h2>
<p><?=$paginator->counter(); ?></p>

<table cellpadding=quot;0quot; cells...
An MVC Quickie
The Fun Stuff
Ajax!
• Normal Link:
  $html->link(‘Add Post’, ‘/posts/add’);


• Ajax Link:
  $ajax->link(‘Add Post’, ‘/posts/add’, array...
REST & Resources!

• //   config/routes.php
Router::mapResources(“posts”);

Router::parseExtensions(“rss”, “js”);

• //   ...
REST & Resources!
// views/posts/xml/index.ctp
<posts>
<?php echo $xml->serialize($posts); ?>
</posts>
// views/posts/xml/...
REST & Resources!
// views/widgets/js/index.ctp
<?php echo $javascript->object($posts); ?>


// views/widgets/js/view.ctp
...
REST & Resources!
GET /posts.xml HTTP/1.1
                            PostsController::index()
GET /posts/1.xml HTTP/1.1
 ...
REST & Resources!
POST /posts.xml HTTP/1.1
Host: www.example.org
Content-Type: text/xml; charset=utf-8

Content-Length: 67...
The Future...
Upcoming SlideShare
Loading in …5
×

Streamlining Your Applications with Web Frameworks

3,102 views

Published on

Presentation by Nate Abele from CakePHP about web development frameworks.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,102
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
80
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Streamlining Your Applications with Web Frameworks

  1. 1. Streamlining Your Applications with Web Frameworks Kings of Code ~ May 27th, 2008
  2. 2. What is a Web Framework? • “...software framework that is designed to support the development of dynamic websites, Web applications and Web services.” - Wikipedia
  3. 3. What is a Web Framework? • A set of tools and a way to organize them • NOT an application • An abstract base from which to build • NOT a CMS
  4. 4. What is a Web Framework? • Provide libraries for common tasks • Provide structure and convention for your application code • Promote best practices in application design/architecture
  5. 5. Continuum of Structure CakePHP CodeIgniter Zend Framework More Less
  6. 6. Why Use a Framework? • Lets you focus on what’s important • The hard problems have already been solved by people smarter than you • Benefits of community • You (and your requirements) are not special • Chances are, you already do
  7. 7. Why Cake? • For a lot of people and a lot of reasons, Rails = FAIL • Difficult and expensive to deploy • Ahem! scaling... • Programmer availability • PHP is still by far the #1 web language
  8. 8. Why Cake? • “Oh Rasmus, why do you engage in this ‘virtual crap-flinging’? Can’t you lead by example like David Heinemeier Hansson? That guy is the height of maturity and an expert scalability guy.” “...look at the top 100 websites on the internet: about 40% of them are written in PHP and 0% of them are written in Rails.” - Terry Chay
  9. 9. Why Cake? • Other PHP frameworks • Zend Framework • Symfony • PHP on Trax • CodeIgniter
  10. 10. An MVC Quickie Dispatcher The Dispatcher requests the appropriate Controller/action, which interacts with the Model Controller Model The Controller then sends the results of its operations to the View view, where it is rendered
  11. 11. An MVC Quickie • Primary: separation between Controller and View, to partition business logic and presentation • Secondary: separation between data (Model) and Controller
  12. 12. An MVC Quickie A simple example /* models/post.php */ class Post extends AppModel { } /* controllers/posts_controller.php */ class PostsController extends AppController { function index() { // Get the data from the Model $posts = $this->paginate(); // Send the data to the view $this->set(compact(‘posts’)); } }
  13. 13. <div class=quot;posts indexquot;> <h2>Posts</h2> <p><?=$paginator->counter(); ?></p> <table cellpadding=quot;0quot; cellspacing=quot;0quot;> <tr> <th><?=$paginator->sort('id'); ?></th> <th><?=$paginator->sort('title'); ?></th> <th><?=$paginator->sort('body'); ?></th> ... <th class=quot;actionsquot;>Actions</th> </tr> <? foreach ($posts as $post) { ?> <tr> <td><?=$post->id; ?></td> <td><?=$post->title; ?></td> <td><?=$post->body; ?></td> .... <td class=quot;actionsquot;>...</td> </tr> <? } ?> </table> <div class=quot;pagingquot;> <?=$paginator->prev('<< previous', array(), null, array('class' => 'disabled')); ?> | <?=$paginator->numbers(); ?> <?=$paginator->next('next >>', array(), null, array('class' => 'disabled')); ?> </div>
  14. 14. An MVC Quickie
  15. 15. The Fun Stuff
  16. 16. Ajax! • Normal Link: $html->link(‘Add Post’, ‘/posts/add’); • Ajax Link: $ajax->link(‘Add Post’, ‘/posts/add’, array( ‘update’ => ‘addPostDiv’, ‘complete’ => ‘Effect.SlideDown(“addPostDiv”)’ ));
  17. 17. REST & Resources! • // config/routes.php Router::mapResources(“posts”); Router::parseExtensions(“rss”, “js”); • // app_controller.php var $components = array(“RequestHandler”);
  18. 18. REST & Resources! // views/posts/xml/index.ctp <posts> <?php echo $xml->serialize($posts); ?> </posts> // views/posts/xml/view.ctp <?php echo $xml->serialize($posts); ?>
  19. 19. REST & Resources! // views/widgets/js/index.ctp <?php echo $javascript->object($posts); ?> // views/widgets/js/view.ctp <?php echo $javascript->object($posts); ?>
  20. 20. REST & Resources! GET /posts.xml HTTP/1.1 PostsController::index() GET /posts/1.xml HTTP/1.1 PostsController::view(1) POST /posts.xml HTTP/1.1 PostsController::add() PUT /posts/1.xml HTTP/1.1 PostsController::edit(1) DELETE /posts/1.xml HTTP/1.1 PostsController::delete(1)
  21. 21. REST & Resources! POST /posts.xml HTTP/1.1 Host: www.example.org Content-Type: text/xml; charset=utf-8 Content-Length: 67 <?xml version=“1.0”?> <post title=“XML” body=“New Post from XML” />
  22. 22. The Future...

×