Creating pages using the page factoryΒΆ

All pages (also custom classes), can be created using the page factory, Zend\Navigation\Page\AbstractPage::factory(). The factory can take an array with options, or a Zend\Config object. Each key in the array/config corresponds to a page option, as seen in the section on Pages. If the option uri is given and no MVC options are given (action, controller, route), an URI page will be created. If any of the MVC options are given, an MVC page will be created.

If type is given, the factory will assume the value to be the name of the class that should be created. If the value is mvc or uri and MVC/URI page will be created.

Creating an MVC page using the page factory

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label'  => 'My MVC page',
    'action' => 'index',
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label'      => 'Search blog',
    'action'     => 'index',
    'controller' => 'search',
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label' => 'Home',
    'route' => 'home',
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'type'   => 'mvc',
    'label'  => 'My MVC page',
));

Creating a URI page using the page factory

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label' => 'My URI page',
    'uri'   => 'http://www.example.com/',
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label'  => 'Search',
    'uri'    => 'http://www.example.com/search',
    'active' => true,
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'label' => 'My URI page',
    'uri'   => '#',
));

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'type'  => 'uri',
    'label' => 'My URI page',
));

Creating a custom page type using the page factory

To create a custom page type using the factory, use the option type to specify a class name to instantiate.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class My\Navigation\Page extends Zend\Navigation\Page\AbstractPage
{
    protected $_fooBar = 'ok';

    public function setFooBar($fooBar)
    {
        $this->_fooBar = $fooBar;
    }
}

$page = Zend\Navigation\Page\AbstractPage::factory(array(
    'type'    => 'My\Navigation\Page',
    'label'   => 'My custom page',
    'foo_bar' => 'foo bar',
));

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Creating pages using the page factory on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.