O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pro PHP MVC

Book Description

Model View Controller (MVC) is becoming the definitive architecture of website development frameworks due to the stability, extensibility and predictability it lends to development. It is not just the primary separation of database, business logic and interface components, but includes a wide range of considerations for building high-performing, scalable and secure applications.

Deciding which MVC framework best suits the project you are about to begin is one of the biggest challenges you'll face as a developer. If you are part of a team, this decision has probably already been made for you; but in any event, you'll need to know how (and why) the framework authors made it work the way it does.

Pro PHP MVC looks at the building blocks that make any good MVC framework, and how they apply to PHP. It exposes all considerations that many developers take for granted when using a popular framework, and teaches you how to make the framework your own.

Over the course of reading this book, you will learn the theoretical implications of the choices you would make when writing your own MVC framework, and how to put the pieces together in a cohesive package. We take a look at the highly modular Zend Framework—how to use its collection of loosely coupled classes to build a unified system. We also look at CakePHP, learning from its automated build system (Bakery) and highly intuitive approach to rapid development. This book will lay bare all the secret parts of MVC for you.

What you'll learn

  • The best way to structure your application files

  • How to get from a URL to the right controller/action

  • Cleanly interact with data objects

  • Efficient use of server resources in content delivery

  • Useful shared class libraries to speed up development

  • Unit testing to ensure maximum stability

  • Who this book is for

    This book is for beginners and advanced developers alike, requiring a basic understanding of PHP5 language features and SQL. If you want to improve your PHP skills, or share the wisdom of popular PHP MVC frameworks, this book will be invaluable to you.

    Table of Contents

    1. Titlepage
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Author
    6. About the Technical Reviewer
    7. Acknowledgments
    8. Introduction
    9. Chapter 1: Introduction to MVC
      1. What Is MVC?
      2. Benefits of MVC
      3. Popular MVC Frameworks
      4. Design Patterns
      5. Creating Our Own Framework
      6. Goals
    10. Chapter 2: Foundation
      1. Goals
      2. Autoloading
      3. Exceptions
      4. Type Methods
      5. Metadata
      6. Questions
      7. Answers
      8. Exercises
    11. Chapter 3: Base Class
      1. Goals
      2. Getters and Setters
      3. Magic Methods
      4. Adding Introspection
      5. Transparent Getters/Setters
      6. Questions
      7. Answers
      8. Exercises
    12. Chapter 4: Configuration
      1. Goals
      2. Associative Arrays
      3. INI Files
      4. Questions
      5. Answers
      6. Exercises
    13. Chapter 5: Caching
      1. Goals
      2. Performance Bottlenecks
      3. The Code
      4. Questions
      5. Answers
      6. Exercises
    14. Chapter 6: Registry
      1. Goals
      2. Singleton
      3. Registry
      4. Questions
      5. Answers
      6. Exercises
    15. Chapter 7: Routing
      1. Goals
      2. Defining Routes
      3. Route Classes
      4. Router Class
      5. Questions
      6. Answers
      7. Exercises
    16. Chapter 8: Templates
      1. Goals
      2. Idea
      3. Alternatives
      4. Implementation
      5. Benefits
      6. Questions
      7. Answers
      8. Exercises
    17. Chapter 9: Databases
      1. Goals
      2. Implementation
      3. Connectors
      4. Queries
      5. Questions
      6. Answers
      7. Exercises
    18. Chapter 10: Models
      1. Goals
      2. Idea
      3. Implementation
      4. Building the SQL
      5. Modifying Records
      6. No Relation of Mine!
      7. Questions
      8. Answers
      9. Exercises
    19. Chapter 11: Testing
      1. Goals
      2. Unit Testing
      3. Test Class
      4. Cache
      5. Configuration
      6. Database
      7. Model
      8. Template
      9. Holy Code, Batman!
      10. Questions
      11. Answers
      12. Exercises
    20. Chapter 12: Structure
      1. Goals
      2. Database
      3. Folders
      4. Questions
      5. Answers
    21. Chapter 13: Bootstrapping
      1. Goals
      2. When a File Is Not a File…
      3. URL Rewriting
      4. Index.php
      5. Configuration
      6. Controller
      7. Questions
      8. Answers
      9. Exercises
    22. Chapter 14: Registration and Login
      1. Goals
      2. Shared Libraries
      3. User Model
      4. Registration
      5. Sessions
      6. Login
      7. Questions
      8. Answers
      9. Exercises
    23. Chapter 15: Search
      1. Goals
      2. Search
      3. Questions
      4. Answers
      5. Exercises
    24. Chapter 16: Settings
      1. Goals
      2. Validation
      3. Settings
      4. Questions
      5. Answers
      6. Exercises
    25. Chapter 17: Sharing
      1. Goals
      2. Error Pages
      3. Friends
      4. Sharing
      5. Questions
      6. Answers
      7. Exercises
    26. Chapter 18: Photos
      1. Goals
      2. How to Upload Files
      3. User Photos
      4. Showing Off, a Little
      5. Questions
      6. Answers
      7. Exercises
    27. Chapter 19: Extending
      1. Goals
      2. Imagine
      3. Observer
      4. Synchronicity
      5. Code
      6. Events
      7. Plugins
      8. Questions
      9. Answers
      10. Exercises
    28. Chapter 20: Administration
      1. Goals
      2. What Is a CMS?
      3. Administrators
      4. Login
      5. Users
      6. Photos
      7. Questions
      8. Answers
      9. Exercises
    29. Chapter 21: Testing
      1. Goals
      2. Questions
      3. Answers
      4. Exercises
    30. Chapter 22: CodeIgniter: Bootstrapping
      1. Goals
      2. Why CodeIgniter?
      3. Why Not CodeIgniter?
      4. URL Rewriting
      5. Routes
      6. Questions
      7. Answers
      8. Exercises
    31. Chapter 23: CodeIgniter: MVC
      1. Goals
      2. Differences
      3. Models
      4. Controllers
      5. Questions
      6. Answers
      7. Exercises
    32. Chapter 24: CodeIgniter: Extending
      1. Goals
      2. File Uploads
      3. Third-Party Libraries
      4. Extending the Core
      5. Questions
      6. Answers
      7. Exercises
    33. Chapter 25: CodeIgniter: Testing
      1. Goals
      2. Tools
      3. The Alternative
      4. Questions
      5. Answers
      6. Exercises
    34. Chapter 26: Zend Framework: Bootstrapping
      1. Goals
      2. Why Zend Framework?
      3. Why Not Zend Framework?
      4. Getting Set Up
      5. Routes
      6. Questions
      7. Answers
      8. Exercises
    35. Chapter 27: Zend Framework: MVC
      1. Goals
      2. The Differences
      3. Models
      4. Controllers
      5. Questions
      6. Answers
      7. Exercises
    36. Chapter 28: Zend Framework: Extending
      1. Goals
      2. File Uploads
      3. Third-Party Libraries
      4. Questions
      5. Answers
      6. Exercises
    37. Chapter 29: Zend Framework: Testing
      1. Goals
      2. Installing PEAR
      3. Installing PHPUnit
      4. Running the Tests
      5. Adding Tests
      6. Questions
      7. Answers
    38. Chapter 30: CakePHP: Bootstrapping
      1. Goals
      2. Why CakePHP?
      3. Why Not CakePHP?
      4. Getting Set Up
      5. Routes
      6. Questions
      7. Answers
      8. Exercises
    39. Chapter 31: CakePHP: MVC
      1. Goals
      2. What’s in a Model?
      3. Controllers
      4. Finishing Up
      5. Questions
      6. Answers
      7. Exercises
    40. Chapter 32: CakePHP: Extending
      1. Goals
      2. File Uploads
      3. Third-Party Libraries
      4. Questions
      5. Answers
      6. Exercises
    41. Chapter 33: CakePHP: Testing
      1. Goals
      2. Testing
      3. Questions
      4. Answers
      5. Exercises
    42. Appendix A: Setting Up a Web Server
      1. Goals
      2. Windows
      3. Linux
      4. MAC OS X
      5. You Passed, with Flying Colors!
    43. Index