Zend Framework 2 Logo
latest
  • Overview
  • Installation
  • Getting Started with Zend Framework 2
  • Getting started: A skeleton application
  • Modules
  • Routing and controllers
  • Create the controller
  • Database and models
  • Styling and Translations
  • Forms and actions
  • Conclusion
  • Introducing our first “Blog” Module
  • Introducing Services and the ServiceManager
  • Preparing for different Database-Backends
  • Introducing Zend\Db\Sql and Zend\Stdlib\Hydrator
  • Understanding the Router
  • Making use of Forms and Fieldsets
  • Editing and Deleting Data
  • Reviewing the Blog-application
  • Getting Started with Zend Framework 2
  • A quick tour of the skeleton application
  • The MyTaskList application
  • The application’s pages
  • Listing tasks
  • Styling
  • Adding new tasks
  • Editing a task
  • Deleting a task
  • Application Diagnostics
  • Step-by-step debugging
  • Conclusion
  • Zend Framework Tool (ZFTool)
  • Learning Dependency Injection
  • Unit Testing a Zend Framework 2 application
  • Using the EventManager
  • Wildcards
  • Listener aggregates
  • Advanced Configuration Tricks
  • Using Zend\Navigation in your Album Module
  • Using Zend\Paginator in your Album Module
  • Using the PaginationControl View Helper
  • Setting up a database adapter
  • Migration from Zend Framework 1
  • Namespacing Old Classes
  • Running Zend Framework 2 and Zend Framework 1 in parallel
  • Introduction to Zend\Authentication
  • Database Table Authentication
  • Digest Authentication
  • HTTP Authentication Adapter
  • LDAP Authentication
  • Authentication Validator
  • Introduction to Zend\Barcode
  • Barcode creation using Zend\Barcode\Barcode class
  • Zend\Barcode Objects
  • Zend\Barcode Renderers
  • Zend\Cache\Storage\Adapter
  • Zend\Cache\Storage\Capabilities
  • Zend\Cache\Storage\Plugin
  • Zend\Cache\Pattern
  • Zend\Cache\Pattern\CallbackCache
  • Zend\Cache\Pattern\ClassCache
  • Zend\Cache\Pattern\ObjectCache
  • Zend\Cache\Pattern\OutputCache
  • Zend\Cache\Pattern\CaptureCache
  • Introduction to Zend\Captcha
  • Captcha Operation
  • CAPTCHA Adapters
  • Introduction
  • Zend\Code\Generator Reference
  • Zend\Code\Generator Examples
  • Introduction to Zend\Config
  • Theory of Operation
  • Zend\Config\Reader
  • Zend\Config\Writer
  • Zend\Config\Processor
  • The Factory
  • Introduction to Zend\Console
  • Console routes and routing
  • Console-aware modules
  • Console-aware action controllers
  • Console adapters
  • Console prompts
  • Zend\Console\Getopt
  • Declaring Getopt Rules
  • Fetching Options and Arguments
  • Configuring Zend\Console\Getopt
  • Introduction to Zend\Crypt
  • Encrypt/decrypt using block ciphers
  • Encrypt/decrypt a file
  • Key derivation function
  • Password
  • Public key cryptography
  • Zend\Db\Adapter
  • Zend\Db\ResultSet
  • Zend\Db\Sql
  • Zend\Db\Sql\Ddl
  • Zend\Db\TableGateway
  • Zend\Db\RowGateway
  • Zend\Db\Metadata
  • Dumping Variables
  • Introduction to Zend\Di
  • Zend\Di Quickstart
  • Zend\Di Definition
  • Zend\Di InstanceManager
  • Zend\Di Configuration
  • Zend\Di Debugging & Complex Use Cases
  • Introduction to Zend\Dom
  • Zend\Dom\Query
  • Introduction to Zend\Escaper
  • Theory of Operation
  • Configuring Zend\Escaper
  • Escaping HTML
  • Escaping HTML Attributes
  • Escaping Javascript
  • Escaping Cascading Style Sheets
  • Escaping URLs
  • The EventManager
  • Introduction to Zend\Feed
  • Importing Feeds
  • Retrieving Feeds from Web Pages
  • Consuming an RSS Feed
  • Consuming an Atom Feed
  • Consuming a Single Atom Entry
  • Zend\Feed and Security
  • Zend\Feed\Reader\Reader
  • Zend\Feed\Writer\Writer
  • Zend\Feed\PubSubHubbub
  • Zend\File\ClassFileLocator
  • Introduction to Zend\Filter
  • Standard Filter Classes
  • Word Filters
  • File Filter Classes
  • Filter Chains
  • Zend\Filter\Inflector
  • Using the StaticFilter
  • Writing Filters
  • Introduction
  • Quick Start
  • Form Collections
  • File Uploading
  • Advanced use of forms
  • Form Elements
  • Form View Helpers
  • Zend\Http
  • The Request Class
  • The Response Class
  • The Headers Class
  • HTTP Client
  • HTTP Client - Connection Adapters
  • HTTP Client - Advanced Usage
  • HTTP Client - Static Usage
  • Translating
  • I18n View Helpers
  • I18n Filters
  • I18n Validators
  • Alnum Validator
  • Alpha Validator
  • IsFloat
  • Introduction
  • Input filter specifications
  • File Upload Input
  • Introduction
  • Basic Usage
  • Advanced Usage
  • XML to JSON conversion
  • Zend\Json\Server - JSON-RPC server
  • Introduction to Zend\Ldap
  • API overview
  • Zend\Ldap\Ldap
  • Zend\Ldap\Attribute
  • Zend\Ldap\Converter\Converter
  • Zend\Ldap\Dn
  • Zend\Ldap\Filter
  • Zend\Ldap\Node
  • Zend\Ldap\Node\RootDse
  • Zend\Ldap\Node\Schema
  • Zend\Ldap\Ldif\Encoder
  • Usage Scenarios
  • Tools
  • Object-oriented access to the LDAP tree using Zend\Ldap\Node
  • Getting information from the LDAP server
  • Serializing LDAP data to and from LDIF
  • The AutoloaderFactory
  • The StandardAutoloader
  • The ClassMapAutoloader
  • The ModuleAutoloader
  • The SplAutoloader Interface
  • The PluginClassLoader
  • The ShortNameLocator Interface
  • The PluginClassLocator interface
  • The Class Map Generator utility: bin/classmap_generator.php
  • Zend\Log
  • Writers
  • Filters
  • Formatters
  • Introduction to Zend\Mail
  • Zend\Mail\Message
  • Zend\Mail\Transport
  • Zend\Mail\Transport\SmtpOptions
  • Zend\Mail\Transport\FileOptions
  • Introduction to Zend\Math
  • Overview
  • Memory Manager
  • Memory Objects
  • Zend\Mime
  • Zend\Mime\Message
  • Zend\Mime\Part
  • Introduction to the Module System
  • The Module Manager
  • The Module Class
  • The Module Autoloader
  • Best Practices when Creating Modules
  • Introduction to the MVC Layer
  • Quick Start
  • Default Services
  • Routing
  • The MvcEvent
  • The SendResponseEvent
  • Available Controllers
  • Controller Plugins
  • Examples
  • Introduction to Zend\Navigation
  • Quick Start
  • Pages
  • Containers
  • View Helpers
  • View Helper - Breadcrumbs
  • View Helper - Links
    • Introduction
    • Basic usage
      • Specify relations in pages
      • Default rendering of links
      • Specify which relations to render
  • View Helper - Menu
  • View Helper - Sitemap
  • View Helper - Navigation Proxy
  • Introduction to Zend\Paginator
  • Usage
  • Configuration
  • Advanced usage
  • Introduction to Zend\Permissions\Acl
  • Refining Access Controls
  • Advanced Usage
  • Introduction to Zend\Permissions\Rbac
  • Methods
  • Examples
  • Progress Bars
  • File Upload Handlers
  • Introduction to Zend\Serializer
  • Zend\Serializer\Adapter
  • Introduction to Zend\Server
  • Zend\Server\Reflection
  • Zend\ServiceManager
  • Zend\ServiceManager Quick Start
  • Delegator service factories
  • Lazy Services
  • Session Config
  • Session Container
  • Session Manager
  • Session Save Handlers
  • Session Storage
  • Session Validators
  • Zend\Soap\Server
  • Zend\Soap\Client
  • WSDL Accessor
  • AutoDiscovery
  • Zend\Stdlib\Hydrator
  • Zend\Stdlib\Hydrator\Filter
  • Zend\Stdlib\Hydrator\Strategy
  • AggregateHydrator
  • CompositeNamingStrategy
  • IdentityNamingStrategy
  • MapNamingStrategy
  • UnderscoreNamingStrategy
  • Introduction to Zend\Tag
  • Creating tag clouds with Zend\Tag\Cloud
  • Introduction to Zend\Test
  • Unit testing with PHPUnit
  • Zend\Text\Figlet
  • Zend\Text\Table
  • Zend\Uri
  • Introduction to Zend\Validator
  • Standard Validation Classes
  • Alnum Validator
  • Alpha Validator
  • Barcode Validator
  • Between Validator
  • Callback Validator
  • Date Validator
  • Db\RecordExists and Db\NoRecordExists Validators
  • Digits Validator
  • File Validation Classes
  • Hex Validator
  • Hostname Validator
  • Iban Validator
  • Identical Validator
  • Ip Validator
  • Isbn Validator
  • IsInstanceOf Validator
  • IsFloat
  • IsInt
  • Regex Validator
  • Sitemap Validators
  • Step Validator
  • Timezone Validator
  • Uri Validator
  • Validator Chains
  • Writing Validators
  • Validation Messages
  • Getting the Zend Framework Version
  • Zend\View Quick Start
  • The PhpRenderer
  • PhpRenderer View Scripts
  • The ViewEvent
  • View Helpers
  • View Helper - BasePath
  • View Helper - Cycle
  • View Helper - Doctype
  • FlashMessenger Helper
  • Gravatar Helper
  • View Helper - HeadLink
  • View Helper - HeadMeta
  • View Helper - HeadScript
  • View Helper - HeadStyle
  • View Helper - HeadTitle
  • View Helper - HtmlList
  • View Helper - HTML Object
  • View Helper - Identity
  • View Helper - InlineScript
  • View Helper - JSON
  • View Helper - Partial
  • View Helper - Placeholder
  • View Helper - URL
  • Advanced usage of helpers
  • Introduction to Zend\XmlRpc
  • Zend\XmlRpc\Client
  • Zend\XmlRpc\Server
  • ZendService\Akismet
  • ZendService\Amazon
  • ZendService\Amazon\S3
  • ZendService\Amazon\Sqs
  • ZendService\Amazon\Ec2
  • ZendService\Amazon\Ec2: CloudWatch Monitoring
  • ZendService\Amazon\Ec2: Elastic Block Storage (EBS)
  • ZendService\Amazon\Ec2: Elastic IP Addresses
  • ZendService\Amazon\Ec2: Instances
  • ZendService\Amazon\Ec2: Regions and Availability Zones
  • ZendService\Amazon\Ec2: Reserved Instances
  • ZendService\Amazon\Ec2: Security Groups
  • ZendService\Amazon\Ec2: Windows Instances
  • ZendService\Apple\Apns
  • ZendService\Audioscrobbler
  • ZendService\Delicious
  • ZendService\DeveloperGarden
  • ZendService\Flickr
  • ZendService\Google\Gcm
  • ZendService\LiveDocx
  • ZendService\Rackspace
  • ZendService\Rackspace\Servers
  • ZendService\Rackspace\Files
  • ZendService\ReCaptcha
  • ZendService\SlideShare
  • ZendService\StrikeIron
  • ZendService\StrikeIron: Bundled Services
  • ZendService\StrikeIron: Advanced Uses
  • ZendService\Technorati
  • ZendService\Twitter
  • ZendService\WindowsAzure
  • ZendService\WindowsAzure\Storage\Blob
  • ZendService\WindowsAzure\Storage\Table
  • ZendService\WindowsAzure\StorageQueue
  • Copyright Information
Zend Framework 2
  • Docs »
  • View Helper - Links
  • Edit on GitHub

View Helper - Links¶

Introduction¶

The links helper is used for rendering HTML LINK elements. Links are used for describing document relationships of the currently active page. Read more about links and link types at Document relationships: the LINK element (HTML4 W3C Rec.) and Link types (HTML4 W3C Rec.) in the HTML4 W3C Recommendation.

There are two types of relations; forward and reverse, indicated by the kewyords ‘rel’ and ‘rev’. Most methods in the helper will take a $rel param, which must be either ‘rel’ or ‘rev’. Most methods also take a $type param, which is used for specifying the link type (e.g. alternate, start, next, prev, chapter, etc).

Relationships can be added to page objects manually, or found by traversing the container registered in the helper. The method findRelation($page, $rel, $type) will first try to find the given $rel of $type from the $page by calling $page->findRel($type) or $page->findRel($type). If the $page has a relation that can be converted to a page instance, that relation will be used. If the $page instance doesn’t have the specified $type, the helper will look for a method in the helper named search$rel$type (e.g. searchRelNext() or searchRevAlternate()). If such a method exists, it will be used for determining the $page’s relation by traversing the container.

Not all relations can be determined by traversing the container. These are the relations that will be found by searching:

  • searchRelStart(), forward ‘start’ relation: the first page in the container.
  • searchRelNext(), forward ‘next’ relation; finds the next page in the container, i.e. the page after the active page.
  • searchRelPrev(), forward ‘prev’ relation; finds the previous page, i.e. the page before the active page.
  • searchRelChapter(), forward ‘chapter’ relations; finds all pages on level 0 except the ‘start’ relation or the active page if it’s on level 0.
  • searchRelSection(), forward ‘section’ relations; finds all child pages of the active page if the active page is on level 0 (a ‘chapter’).
  • searchRelSubsection(), forward ‘subsection’ relations; finds all child pages of the active page if the active pages is on level 1 (a ‘section’).
  • searchRevSection(), reverse ‘section’ relation; finds the parent of the active page if the active page is on level 1 (a ‘section’).
  • searchRevSubsection(), reverse ‘subsection’ relation; finds the parent of the active page if the active page is on level 2 (a ‘subsection’).

Note

When looking for relations in the page instance ($page->getRel($type) or $page->getRev($type)), the helper accepts the values of type String, Array, Zend\Config, or Zend\Navigation\Page\AbstractPage. If a string is found, it will be converted to a Zend\Navigation\Page\Uri. If an array or a config is found, it will be converted to one or several page instances. If the first key of the array/config is numeric, it will be considered to contain several pages, and each element will be passed to the page factory. If the first key is not numeric, the array/config will be passed to the page factory directly, and a single page will be returned.

The helper also supports magic methods for finding relations. E.g. to find forward alternate relations, call $helper->findRelAlternate($page), and to find reverse section relations, call $helper->findRevSection($page). Those calls correspond to $helper->findRelation($page, ‘rel’, ‘alternate’); and $helper->findRelation($page, ‘rev’, ‘section’); respectively.

To customize which relations should be rendered, the helper uses a render flag. The render flag is an integer value, and will be used in a bitwise and (&) operation against the helper’s render constants to determine if the relation that belongs to the render constant should be rendered.

See the example below for more information.

  • Zend\View\Helper\Navigation\Links::RENDER_ALTERNATE
  • Zend\View\Helper\Navigation\Links::RENDER_STYLESHEET
  • Zend\View\Helper\Navigation\Links::RENDER_START
  • Zend\View\Helper\Navigation\Links::RENDER_NEXT
  • Zend\View\Helper\Navigation\Links::RENDER_PREV
  • Zend\View\Helper\Navigation\Links::RENDER_CONTENTS
  • Zend\View\Helper\Navigation\Links::RENDER_INDEX
  • Zend\View\Helper\Navigation\Links::RENDER_GLOSSARY
  • Zend\View\Helper\Navigation\Links::RENDER_COPYRIGHT
  • Zend\View\Helper\Navigation\Links::RENDER_CHAPTER
  • Zend\View\Helper\Navigation\Links::RENDER_SECTION
  • Zend\View\Helper\Navigation\Links::RENDER_SUBSECTION
  • Zend\View\Helper\Navigation\Links::RENDER_APPENDIX
  • Zend\View\Helper\Navigation\Links::RENDER_HELP
  • Zend\View\Helper\Navigation\Links::RENDER_BOOKMARK
  • Zend\View\Helper\Navigation\Links::RENDER_CUSTOM
  • Zend\View\Helper\Navigation\Links::RENDER_ALL

The constants from RENDER_ALTERNATE to RENDER_BOOKMARK denote standard HTML link types. RENDER_CUSTOM denotes non-standard relations that specified in pages. RENDER_ALL denotes standard and non-standard relations.

Methods in the links helper:

  • {get|set}RenderFlag() gets/sets the render flag. Default is RENDER_ALL. See examples below on how to set the render flag.
  • findAllRelations() finds all relations of all types for a given page.
  • findRelation() finds all relations of a given type from a given page.
  • searchRel{Start|Next|Prev|Chapter|Section|Subsection}() traverses a container to find forward relations to the start page, the next page, the previous page, chapters, sections, and subsections.
  • searchRev{Section|Subsection}() traverses a container to find reverse relations to sections or subsections.
  • renderLink() renders a single link element.

Basic usage¶

Specify relations in pages¶

This example shows how to specify relations in pages.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$container = new Zend\Navigation\Navigation(array(
    array(
        'label' => 'Relations using strings',
        'rel'   => array(
            'alternate' => 'http://www.example.org/'
        ),
        'rev'   => array(
            'alternate' => 'http://www.example.net/'
        )
    ),
    array(
        'label' => 'Relations using arrays',
        'rel'   => array(
            'alternate' => array(
                'label' => 'Example.org',
                'uri'   => 'http://www.example.org/'
            )
        )
    ),
    array(
        'label' => 'Relations using configs',
        'rel'   => array(
            'alternate' => new Zend\Config\Config(array(
                'label' => 'Example.org',
                'uri'   => 'http://www.example.org/'
            ))
        )
    ),
    array(
        'label' => 'Relations using pages instance',
        'rel'   => array(
            'alternate' => Zend\Navigation\Page\AbstractPage::factory(array(
                'label' => 'Example.org',
                'uri'   => 'http://www.example.org/'
            ))
        )
    )
));

Default rendering of links¶

This example shows how to render a menu from a container registered/found in the view helper.

In a view script or layout:

1
<?php echo $this->view->navigation()->links(); ?>

Output:

1
2
3
4
5
6
7
8
9
<link rel="alternate" href="/products/server/faq/format/xml">
<link rel="start" href="/" title="Home">
<link rel="next" href="/products/server/editions" title="Editions">
<link rel="prev" href="/products/server" title="Foo Server">
<link rel="chapter" href="/products" title="Products">
<link rel="chapter" href="/company/about" title="Company">
<link rel="chapter" href="/community" title="Community">
<link rel="canonical" href="http://www.example.com/?page=server-faq">
<link rev="subsection" href="/products/server" title="Foo Server">

Specify which relations to render¶

This example shows how to specify which relations to find and render.

Render only start, next, and prev:

1
2
3
$helper->setRenderFlag(Zend\View\Helper\Navigation\Links::RENDER_START |
                       Zend\View\Helper\Navigation\Links::RENDER_NEXT |
                       Zend\View\Helper\Navigation\Links::RENDER_PREV);

Output:

1
2
3
<link rel="start" href="/" title="Home">
<link rel="next" href="/products/server/editions" title="Editions">
<link rel="prev" href="/products/server" title="Foo Server">

Render only native link types:

1
2
$helper->setRenderFlag(Zend\View\Helper\Navigation\Links::RENDER_ALL ^
                       Zend\View\Helper\Navigation\Links::RENDER_CUSTOM);

Output:

1
2
3
4
5
6
7
8
<link rel="alternate" href="/products/server/faq/format/xml">
<link rel="start" href="/" title="Home">
<link rel="next" href="/products/server/editions" title="Editions">
<link rel="prev" href="/products/server" title="Foo Server">
<link rel="chapter" href="/products" title="Products">
<link rel="chapter" href="/company/about" title="Company">
<link rel="chapter" href="/community" title="Community">
<link rev="subsection" href="/products/server" title="Foo Server">

Render all but chapter:

1
2
$helper->setRenderFlag(Zend\View\Helper\Navigation\Links::RENDER_ALL ^
                       Zend\View\Helper\Navigation\Links::RENDER_CHAPTER);

Output:

1
2
3
4
5
6
<link rel="alternate" href="/products/server/faq/format/xml">
<link rel="start" href="/" title="Home">
<link rel="next" href="/products/server/editions" title="Editions">
<link rel="prev" href="/products/server" title="Foo Server">
<link rel="canonical" href="http://www.example.com/?page=server-faq">
<link rev="subsection" href="/products/server" title="Foo Server">
Next Previous

© Copyright 2015, Zend Technologies Ltd.. Revision 05d48172.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
release-2.0.0rc4
release-2.0.0rc3
release-2.0.0rc2
release-2.0.0rc1
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
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 View Helper - Links 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.