PHPackages                             petrgrishin/yii-url-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. petrgrishin/yii-url-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

petrgrishin/yii-url-builder
===========================

Url builder

1.0.0(12y ago)222MITPHPPHP &gt;=5.3.0

Since Jun 14Pushed 12y ago1 watchersCompare

[ Source](https://github.com/petrgrishin/yii-url-builder)[ Packagist](https://packagist.org/packages/petrgrishin/yii-url-builder)[ RSS](/packages/petrgrishin-yii-url-builder/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

yii-url-builder
===============

[](#yii-url-builder)

[![Travis CI](https://camo.githubusercontent.com/97f61c735576e512bb9154d1ea7b0b78eff5d4684fafb675561c1e2208915a32/68747470733a2f2f7472617669732d63692e6f72672f706574726772697368696e2f7969692d75726c2d6275696c6465722e706e67 "Travis CI")](https://travis-ci.org/petrgrishin/yii-url-builder)[![Coverage Status](https://camo.githubusercontent.com/0f9badcd61a24a985ea87b4cfccfdaf9efefc6803e580c6f6f9116c8f388c538/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f706574726772697368696e2f7969692d75726c2d6275696c6465722f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/petrgrishin/yii-url-builder?branch=master)

Url builder

Установка
---------

[](#установка)

Добавите зависимость для вашего проекта в composer.json:

```
{
    "require": {
        "petrgrishin/yii-url-builder": "~1.0"
    }
}
```

Постановка проблемы
-------------------

[](#постановка-проблемы)

Необходимо определить знание об адресе контроллеров в одном слое сисстемы. Это позволит быстро и безболезненно производить поиск и рефакторинг контроллеров и их адресов.

Реализовать проверку достаточности параметров построения адреса, если такое происходит в другом слое, например в представлении или клиентских скриптах.

Решение
-------

[](#решение)

Все адреса контроллеров должны быть определены в самих контроллерах. При необходимости недостающие параметры можно заполнить в слое представления или клиентского скрипта. Для удобной работы необходимо определить помощника - построитель адресов.

Примеры использования
---------------------

[](#примеры-использования)

#### Определение знания об адресе в контроллере

[](#определение-знания-об-адресе-в-контроллере)

Базовый абстрактный контроллер. Реализация метода создания обектов построителя адреса

```
class BaseController extends \CController {

    public function createUrlBuilder($route, $params = array()) {
        $urlBuilder = new UrlBuilder($this->getUrlManager());
        $urlBuilder
            ->setRoute($route)
            ->setParams($params);
        return $urlBuilder;
    }

    public function getUrlManager() {
        $urlManager = $this->getApp()->getUrlManager();
        return $urlManager;
    }

    public function getApp() {
        return \Yii::app();
    }
}
```

Конкретный контроллер. Использование построителя адреса

```
class SiteController extends BaseController {

    public function actionIndex() {
        return $this->render('index', array(
            'urls' => array(
                'catalog' => $this->createUrlBuilder('site/catalog')
                    ->getUrl(),
                // передана готовая строка адреса ?r=site/catalog
            ),
        ));
    }

    public function actionCatalog() {
        return $this->render('about', array(
            'products' => Product::model()->findAll(),
            'urls' => array(
                'product' => $this->createUrlBuilder('site/product')
                    ->setRequired(array('id')),
                // передан объект построителя с необходимыми знаниями,
                // требуемые параметры заполняются в представлении
            ),
        ));
    }

    public function actionProduct($id) {
        return $this->render('product');
    }
}
```

Представление вывода каталога товаров

```
/** @var UrlBuilder $productUrlBuilder */
$productUrlBuilder = $this->getParam('urls.product');

foreach ($this->getParam('products') as $product) {
    $productUrl = $productUrlBuilder
        ->copy()
        ->setParam('id', $product->id)
        ->getUrl();

    print($productUrl);
    // строка адреса ?r=site/product&id=1
}

// или передать параметры построителя адреса в клиентский скрипт
$this->setJsParams(array(
    'urls' => array(
        'product' => $productUrlBuilder->toArray(),
    ),
));
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4403d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/580229?v=4)[Petr Grishin](/maintainers/petrgrishin)[@petrgrishin](https://github.com/petrgrishin)

---

Top Contributors

[![petrgrishin](https://avatars.githubusercontent.com/u/580229?v=4)](https://github.com/petrgrishin "petrgrishin (15 commits)")

### Embed Badge

![Health badge](/badges/petrgrishin-yii-url-builder/health.svg)

```
[![Health](https://phpackages.com/badges/petrgrishin-yii-url-builder/health.svg)](https://phpackages.com/packages/petrgrishin-yii-url-builder)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
