<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.navigation.pages.custom">
    <title>Creating custom page types</title>

    <para>
        When extending <classname>Zend_Navigation_Page</classname>, there is
        usually no need to override the constructor or the methods
        <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname>. The page
        constructor takes a single parameter, an <type>Array</type> or a
        <classname>Zend_Config</classname> object, which is passed to
        <methodname>setOptions()</methodname> or <methodname>setConfig()</methodname> respectively.
        Those methods will in turn call <methodname>set()</methodname> method, which
        will map options to native or custom properties. If the option
        <property>internal_id</property> is given, the method will first look for a
        method named <methodname>setInternalId()</methodname>, and pass the option to this
        method if it exists. If the method does not exist, the option will be
        set as a custom property of the page, and be accessible via
        <command>$internalId = $page->internal_id;</command> or
        <command>$internalId = $page->get('internal_id');</command>.
    </para>

    <example id="zend.navigation.custom.example.simple">
        <title>The most simple custom page</title>

        <para>
            The only thing a custom page class needs to implement is the
            <methodname>getHref()</methodname> method.
        </para>

        <programlisting language="php"><![CDATA[
class My_Simple_Page extends Zend_Navigation_Page
{
    public function getHref()
    {
        return 'something-completely-different';
    }
}
]]></programlisting>
    </example>

    <example id="zend.navigation.custom.example.properties">
        <title>A custom page with properties</title>

        <para>
            When adding properties to an extended page, there is no need
            to override/modify <methodname>setOptions()</methodname> or
            <methodname>setConfig()</methodname>.
        </para>

        <programlisting language="php"><![CDATA[
class My_Navigation_Page extends Zend_Navigation_Page
{
    private $_foo;
    private $_fooBar;

    public function setFoo($foo)
    {
        $this->_foo = $foo;
    }

    public function getFoo()
    {
        return $this->_foo;
    }

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

    public function getFooBar()
    {
        return $this->_fooBar;
    }

    public function getHref()
    {
        return $this->foo . '/' . $this->fooBar;
    }
}

// can now construct using
$page = new My_Navigation_Page(array(
    'label'   => 'Property names are mapped to setters',
    'foo'     => 'bar',
    'foo_bar' => 'baz'
));

// ...or
$page = Zend_Navigation_Page::factory(array(
    'type'    => 'My_Navigation_Page',
    'label'   => 'Property names are mapped to setters',
    'foo'     => 'bar',
    'foo_bar' => 'baz'
));
]]></programlisting>
    </example>
</sect2>
