snapshotpl/zf-snap-url

此包最新版本(1.1.2)没有可用的许可证信息。

这是为 Zend Framework 2 开发的最短 URL 视图助手! :-)

1.1.2 2014-03-15 13:56 UTC

This package is auto-updated.

Last update: 2024-08-29 04:11:59 UTC


README

这是为 Zend Framework 2 开发的最短 URL 视图助手! :-)

版本 1.1.2 由 Witold Wasiczko 创建

用法

用于路由

user/profile/:id/:slug

实现接口

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(),
                    );
                ),
            },
        );
    }
}

然后在视图中写入以打印用户配置文件 URL

To link user profile (default defined in getRouteName())
<?= $this->u($this->user) ?>
Alias for prev usage
<?= $this->u($this->user, 'profile') ?>
Custom route
<?= $this->u($this->user, 'edit') ?>

没有 ZfSnapUrl,你每次都需要写 这个 (!)

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

如何安装?

通过 composer

{
    "require": {
        "snapshotpl/zf-snap-url": "1.*"
    }
}

测试

composer install --dev

或者

composer update

然后

phpunit --configuration tests/

变更日志

  • 1.1.2 修复了 composer.json 中的 ZF 版本依赖,README 的小幅改进
  • 1.1.1 Travis CI
  • 1.1.0 支持多个路由
  • 1.0.0 带有单元测试的稳定版本