2017 © Pedro Peláez
 

yii2-extension yii2-friendly-url

Friendly url for your library or module

image

maks757/yii2-friendly-url

Friendly url for your library or module

  • Thursday, April 12, 2018
  • by maks757
  • Repository
  • 1 Watchers
  • 0 Stars
  • 48 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 9 % Grown

The README.md

Friendly url

Friendly url for your library or module, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist maks757/yii2-friendly-url "*"

or add, (*4)

"maks757/yii2-friendly-url": "*"

to the require section of your composer.json file., (*5)

Usage

Model

// implements IUrlRules !!!
class ProductModel extends \yii\db\ActiveRecord implements maks757\friendly\components\IUrlRules
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'products';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            //...
            // seo data
            [['seoUrl', 'seoTitle', 'seoDescription', 'seoKeywords'], 'string']
        ];
    }

    // Exemple: $key = 'my-first-product' -> return id
    /**
     * @param mixed $key
     * @return boolean|integer model id
     */
    public function fiendKey($key)
    {
        $model = ProductModel::findOne(['seoUrl' => $key]);
        return empty($model) ? false : $model->id;
    }

    // Exemple: $id = 10 -> return seoUrl
    /**
     * @param integer $id
     * @return string
     */
    public function seoUrl($id)
    {
        return ProductModel::findOne($id)->seoUrl;
    }
}

Configuration

'components' => [
    //...
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            'news' => 'product/show',
            [
                    'class' => \maks757\friendly\UrlRules::className(),
                    'action' => 'product/show', // View 'product/show' or news
                    'controller_and_action' => 'product/show', // Action news show
                    //param: (action_key) - Action param get product id
                    //param: (url_key) - // View set product id
                    'routes' => [
                        ['model' => \common\models\ProductGroupModel::class, 'url_key' => 'group_id', 'action_key' => 'group',],
                        ['model' => \common\models\ProductModel::class, 'url_key' => 'product_id', 'action_key' => 'product',],
                    ]
                ],
        ],
    ],
    //...
],

View

<a href="Url::toRoute(['/product/show', 'group_id' => $group, 'product_id' => $product->id])">Go to product</a>

example url: https://tise/product/show/water/colla
water = group seo url
colla = product seo url
, (*6)

Action from Product Controller

public function actionShow($group, $product)
{
    //...
}

The Versions

12/04 2018

dev-master

9999999-dev

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

09/04 2018

v1.0.0

1.0.0.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

12/01 2018

v1.2.0

1.2.0.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

21/11 2017

v1.1.0

1.1.0.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

14/11 2017

v1.0.1

1.0.1.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

19/09 2017

v0.3.2

0.3.2.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

03/07 2017

v0.3.1

0.3.1.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

03/07 2017

v0.2.2

0.2.2.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

03/07 2017

v0.2.1

0.2.1.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

15/06 2017

v0.2.0

0.2.0.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

01/06 2017

v0.1.1

0.1.1.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

31/05 2017

v0.1.0

0.1.0.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

30/05 2017

v0.0.2

0.0.2.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

30/05 2017

v0.0.3

0.0.3.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url

30/05 2017

v0.0.1

0.0.1.0

Friendly url for your library or module

  Sources   Download

BSD-4-Clause

The Requires

 

by Maxim Cherednyk

url extension yii2 friendly friendly url