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

Overview of Agavi

Agavi is a PHP application framework. It is a rich library of PHP classes and supplemental data. This library provides certain services to you, the application developer. This chapter lists the basic Agavi services that a developer would use or adjust most often.

Agavi Execution Context

Agavi applications execute inside an envelope that's called the "context" of the application. This envelope is exposed to your application as the global singleton Context object.

The Context object is available to all of your code. It is an important object, since you use it to access the global services of the framework. For example, if you wanted to retrieve a named database connection from Agavi DatabaseManager, you'd do it like this:

$db_conn = $this->context->getDatabaseManager()->getDatabase('mydb');

MVC Execution

Developers implement the target applications using the MVC architecture, spending most of their time working with Models, Actions and Views. This tutorial takes a look at these components in great detail.

Application Configuration

Agavi configuration system stores names and their corresponding values. It is a general purpose service that's used both by Agavi applications and the framework itself. The configuration system compiles XML configuration files into executable PHP code. Agavi defines some configuration files for its own purposes. Here's some example code:

// Retrieve a configuration value for item "meaning_of_life" and prefix "org.mycompany.myapp"
// In settings.xml this would be:
//
// <settings prefix="org.mycompany.myapp">
//  <setting name="meaning_of_life">24</setting>
// </setting>
//
// The second parameter is the value that should be returned instead of null

$val = AgaviConfig::get('org.mycompany.myapp.meaning_of_life', 42);
    

Your application can access the configuration through the global AgaviConfig interface. The configuration system supports namespaces, arrays, value interpolation and advanced XML processing features.

Database Access

The framework itself does not need to access databases. It does, however, provide a general database access abstraction mechanism.

When enabled, Agavi's DatabaseManager reads and enacts the application's database configuration. It creates instances of database adapters, through which your Models can access the database servers.

Adapters may interact with low level database APIs or high level third party database libraries. Agavi ships with a number of adapters for most popular APIs, and you can easily write your own adapter if you work with a custom database backend.

$dbm = $this->context->getDatabaseManager();
$db = $dbm->getDatabase('blog');
$conn = $db->getConnection();

Request Dispatcher and Execution Flow

Agavi applications are exposed to the Web server through the front end dispatcher script (typically pub/index.php). The dispatcher reads the requests and starts Agavi execution. Agavi routes the request to the appropriate place in your application.

Several major things happen behind the scenes before the execution is turned over to your application. Various Agavi components are involved in the process of handling the request and composing the response.

Routing

Web applications parse request URLs and invoke certain application actions. Agavi applications do this by specifying a routing map, which describes the URL structure of your application.

The routing mechanism can both construct and analyze URLs. It is extensible and can cope with any conceivable URL structure.

$ro = $this->context->getRouting();

// Generate an absolute URL to a named route 
$url = $ro->gen('posts.edit', array('id' => $post->id), array('relative' => false));

Security and Validation

Validation is Agavi's way to make sure that the request data conforms to certain rules, if these rules are violated, the framework would refuse to execute your code. When used correctly, validation nullifies the threats of malformed data. Validation rules are specified using a special XML language, allowing you to codify the assumptions that your code makes.

On the application level, Agavi provides a security mechanism that understands individual user permissions, allowing to specify who is allowed to access what in your application. Access security is enforced on the framework level as well.

Caching

Agavi has a special caching facility which can spare the execution of unneeded code by reusing data that's already been processed. This gives a great performance boost to real world applications.

Date and Translation Services

Agavi's internationalization services are designed to solve the common problems of maintaining an application in many languages and locales. Agavi translation services are an interface through which your application can transform certain data into their local representation. Thus, Agavi provides strong infrastructure for development of software with fully functional and utilized internationalization features.

Agavi also ships with a date manipulation library.