Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (44 sloc) 1.67 KB


Using DefaultPageLocator

The default page locator uses the following strategy to locate pages:

  1. uppercases the first letter of each word and joining them to a CamelCase like class name
  2. prepending configured namespaces defined via :ref:`page_namespace_prefix <configuration-options>`
  3. returning first found class
$page_locator = new DefaultPageLocator(array('\\shop\\pages', '\\shop\\account\\pages'));
$page_class = $page_locator->resolvePage('Login Page');
$page = new $page_class($page_factory);

Depending on existence either \shop\pages\LoginPage or \shop\account\pages\LoginPage will be returned.

Defining a custom locator

In some cases it might be necessary to build a custom page locator. For example to map page names to specific classes.

.. literalinclude:: examples/custom_page_locator.php

Now it is possible to either locate the page manually by its name:

$page_locator = new MappingPageLocator();
$registration_page_class = $page_locator->resolvePage('Registration Page');
$registration_page = new $registration_page_class($page_factory);

or replace default locator with new one during PageFactory construction time.

$container = new Container();

$container['page_locator'] = function () {
    return new MappingPageLocator();

$page_factory = new PageFactory($session, $container);

$registration_page = $page_factory->getPage('Registration Page');