PHP code example of snapshotpl / zf-snap-url

1. Go to this page and download the library: Download snapshotpl/zf-snap-url 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/ */

    

snapshotpl / zf-snap-url example snippets


class User implements \ZfSnapUrl\Routable {

    /* CODE */

    public function getRouteName() {
        return 'user/profile';
    }

    public function getRouteParams() {
        return array(
            'id'   => $this->getId(),
            'slug' => $this->getSlug(),
        );
    }
}

<?= $this->u($this->user) 

class User implements \ZfSnapUrl\Routable {

    /* CODE */

    public function getRouteName() {
        return 'profile';
    }

    public function getRouteParams() {
        return array(
            'profile' => array(
                'route'  => 'user/profile'
                'params' => array(
                    'id'   => $this->getId(),
                    'slug' => $this->getSlug(),
                );
            ),
            'edit' => function () {
                // You can use closures
                return array(
                    'route'  => 'user/super-long-route-name/edit'
                    'params' => array(
                        'id'   => $this->getId(),
                    );
                ),
            },
        );
    }
}

To link user profile (default defined in getRouteName())
<?= $this->u($this->user) 

<?= $this->url('user/profile', array('id' => $this->user->getId(), 'slug' => $this->user->getSlug()))