2017 © Pedro Peláez
 

library apigility-htmlnegotiation

Apigility HtmlNegotiation module

image

zpetr/apigility-htmlnegotiation

Apigility HtmlNegotiation module

  • Saturday, October 4, 2014
  • by zpetr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 65 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

apigility-htmlnegotiation

HtmlNegotiation module for Apigility., (*1)

Response type is based on Accept header :, (*2)

  • request that specifies text/html (or text/*+html) get the content in HTML
  • application/hal+json (or application/*+json) request get the content in HalJson as usual.

Installation

Install composer in your project, (*3)

curl -s http://getcomposer.org/installer | php

Define dependencies in your composer.json file, (*4)

{
    "require": {
        "zpetr/apigility-htmlnegotiation" : "1.*"
    }
}

Finally install dependencies, (*5)

php composer.phar install

or update it, (*6)

php composer.phar update

Usage

  • Add zPetr\HtmlNegotiation to config/modules.config.php:
    return array(
        'modules' => array(
            ...,
            'zPetr\\HtmlNegotiation',
            ....
        )
    )     
  • Go to admin, select your API and change Content Negotiation Selector to HTML-HalJson
  • Add text/html to Accept whitelist and Content-Type whitelist. Add other headers if needed.
  • Save configuration

Templates

Layout

If you want to personalize custom layout template:, (*7)

  1. Copy default zpetr/apigility-htmlnegotiation/view/layout.phtml template to the view folder of your module (why not to Application module)
  2. Add this to module config:
    ...
    'view_manager' => array(
        'template_map' => array(
            'zpetr/htmlnegotiation/layout'  => __DIR__ . '/../view/layout.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),

API response templates

To customize any API template:, (*8)

  1. Create view folder in your API directory. For example, if you have API named Foo with REST service named Bar, create:
module/Foo/src/Foo/V1/Rest/Bar/view/
  1. Create get.phtml for Entity template and get_list.phtml for Collection template. You can use default ones from zpetr/apigility-htmlnegotiation/view/zf/rest/ folder.

The Versions

04/10 2014

dev-master

9999999-dev https://github.com/zpetr/apigility-htmlnegotiation

Apigility HtmlNegotiation module

  Sources   Download

BSD

The Requires

 

by Petr Glushchenko

api zf2 html module apigility negotiation