PHP code example of effectra / link

1. Go to this page and download the library: Download effectra/link library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

effectra / link example snippets


use Effectra\Link\Link;

$link = new Link('http://example.com', false, ['rel' => 'self'], ['title' => 'Example Link']);

// Add a relation to the link
$link = $link->withRel('next');

// Remove a relation from the link
$link = $link->withoutRel('self');

// Add an attribute to the link
$link = $link->withAttribute('class', 'link-class');

// Remove an attribute from the link
$link = $link->withoutAttribute('title');

use Effectra\Link\LinkProvider;

$link1 = new Link('http://example.com', false, ['rel' => 'self']);
$link2 = new Link('http://example.com/posts', false, ['rel' => 'collection']);

$links = [$link1, $link2];

$linkProvider = new LinkProvider($links, []);

$allLinks = $linkProvider->getLinks(); // Returns an array of LinkInterface objects

$collectionLinks = $linkProvider->getLinksByRel('collection'); // Returns an array of EvolvableLinkInterface objects with the 'collection' relation

$html = $linkProvider->withHTML($links); // Generates an HTML string with links