1. Introduction
    1. About Agavi
    2. MVC in Agavi
    3. Overview of Agavi
    4. Overview of Application Execution Flow
    5. A Word About Actions
    6. Application filesystem layout
    7. Overview of application configuration
  2. Setting Up The Initial Application
    1. Installing Agavi
    2. Creating an Agavi Project
    3. Finishing The Setup
    4. Finishing The Basic Setup
    5. Installing a New Copy of Your Application
  3. Adding First Code
    1. Creating A New module
    2. Creating A New Action
    3. Tying Things Together — An Introduction To Routing
    4. Fixing The Bloggie Routing
    5. Accessing Request Parameters and Validation Basics
    6. Handling Validation Errors
  4. Putting The M in MVC
    1. Creating A New Model
    2. Adapting The Actions and Views
    3. Custom Validators
  5. Polishing It Up
    1. Layers and Layouts
    2. Applying Our Layout
    3. What Are Slots?
    4. Adding The Post's Title To The URL
    5. Routing Callbacks
    6. Using Callbacks for the Title in URLs
  6. Connecting to a database
    1. The Database Manager
  7. Handling Output Variants
    1. Output Types
    2. Exception Templates
    3. Generating an RSS Feed
  8. Form Processing
    1. Adding a Post
    2. Editing a Post
    3. The Form Population Filter (FPF)
  9. Creating a User Authentication System
  10. Adding To The Master Template

MVC in Agavi

MVC and High-Level Application Structure

Agavi implements the Model-View-Controller (MVC) architectural design pattern to provide structure to applications. Agavi's interpretation of MVC is quite conservative, and it is very important that you understand both how the three key parts of the MVC concept come together and how Agavi implements them.

MVC architecture defines three distinct parts of an application. Models contain the application's logic. Controllers interpret requests from the user interface and direct Models. Views question Models, and prepare and send output to the user interface.

The Model-View-Controller architecture offers certain advantages. Without in-depth discussion it is sufficient to say that the MVC approach — combined with Agavi's naming conventions and framework facilities—makes it possible to write dependable, testable and extensible code.

MVC in Agavi

A Model represents an unit of logic in your application. In Agavi, a Model is a PHP class. Its methods solve some sort of application-specific problem: for example, sending promotional emails to customers, or maintaining the customer database. Your application may be implemented entirely inside a single Model or across dozens of Models that represent various areas of your software. Some Models act as wrappers for external libraries and even other applications or interfaces. A newly created Agavi Model is just an empty class.

A Controller component is called an Action in Agavi. Just like Models, Actions are PHP classes. Their methods are called by Agavi at the appropriate time.

Actions have one or more corresponding Views. When a Web request arrives, the routing mechanism selects the initial Action to be executed; the Action performs necessary changes in application state by calling the Models; it also selects ("appoints") one of its Views to be executed after it finishes. After that, the appointed View performs rendering of the application's output.

Since HTTP works under the request-response model, Actions correspond to HTTP request handling, and Views to response compilation.

Note: This relationship does not mean that Agavi applications are restricted to HTTP. Agavi can be used successfully for applications in which no Web interface exists at all. From the practical perspective, all this means is that Views are never executed without an Action.

Actions and Views should not implement any part of the application's domain logic. They serve merely as glue between the user interface, request overhead, and the Models. This means that your entire application sans the user interface should be implemented by using Models.

Actions, Views and Models are grouped into Modules. A Module is simply a directory that contains Actions, Views, templates, module-specific Models, validators, local configuration and whatever else that is only needed by a specific Module. Agavi Modules can be found in your application's app/modules/ directory.

Agavi also has global Models and templates. They reside in app/models/ and app/templates/.