2.2. Front Controller

Once Solar::start() is done, the bootstrap script retrieves a Solar_Controller_Front object from the registry under the name controller_front, and tells it to display the results of its activity. The front controller performs the following steps:

  • As part of instantiation, it gets its own configuration values from the Solar_Config class (these were populated by Solar::start() from the config file).

  • Using the config values from rewrite and replace, it modifies the request URI according to the specified dynamic rewrite rules.

  • It now looks at the first path-info element of the URI to determine what page controller to instantiate. At first, it uses the routing config value to match the element against a particular page controller class. If there are no matches, it tries to automatically pick a class using the classes class stack prefixes.

  • If after all of this, the front controller could not find a page controller class that matched the first element of the URI path info, it will return a "not found" page; otherwise, it will instantiate the page controller class and pass it the (possibly modified) remainder of the URI.

Note that the three layers of modification and discovery (dynamic rewrite, static routing, and class prefixes) are complementary; each can be used by itself alone, or in combination with the others, or not at all.

2.2.1. Dynamic Rewrite

This somewhat complicated topic is covered on the next page.

[Note] Note

Once a rewrite rule is matched, rewrite processing stops and passes along to static routing. Any URI not matching a rewrite rule will be left untouched.

2.2.2. Static Routing

After any dynamic rewrites, the front controller then looks at the first path-info element of the URI and tries route it to a page controller class. It does this in two steps: via static routing, and then via a class stack.

For the static routing, the front controller looks at the routing config value to see if the first path-info element has a page controller class defined for it.

<?php
// routes all "/journal" URIs to the Acme_App_Blog class
$config['Solar_Controller_Front']['routing'] = array(
    'journal' => 'Acme_App_Blog',
);

2.2.3. Class Stack

If there were no static routing matches, the front controller finally falls back to a stack of class prefixes. Solar will append the first path-info element of the URI to each of these in turn, and try to find that class from the include-path. If there are multiple classes in the stack, it will search each one in turn until it finds an existing class.

<?php
// "/zim-gir" will cause the front controller to look for Foo_App_ZimGir,
// then Bar_App_ZimGir, and finally Baz_App_ZimGir.
$config['Solar_Controller_Front']['classes'] = array(
    'classes' => array('Foo_App', 'Bar_App', 'Baz_App'),
);


Local