2017 © Pedro Peláez
 

yii2-extension yii2-cms-alias

Alias module for Yii2

image

infoweb-internet-solutions/yii2-cms-alias

Alias module for Yii2

  • Thursday, August 4, 2016
  • by infoweb-internet-solutions
  • Repository
  • 3 Watchers
  • 0 Stars
  • 726 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Alias module for Yii 2

Installation

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

Either run, (*2)

php composer.phar require infoweb-internet-solutions/yii2-cms-alias "*"

or add, (*3)

"infoweb-internet-solutions/yii2-cms-alias": "*"

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

Usage

Once the extension is installed, simply modify your application configuration as follows:, (*5)

Your backend configuration as follows:, (*6)

'modules' => [
    ...
    'alias' => [
        'class' => 'infoweb\alias\Module',
        'reservedUrls' => ['page'] // Url's that are reserved by the application
    ],
],

Import the translations and use category 'infoweb/alias':, (*7)

yii i18n/import @infoweb/alias/messages

To use the module, execute yii migration, (*8)

yii migrate/up --migrationPath=@vendor/infoweb-internet-solutions/yii2-cms-alias/migrations

Behavior

The AliasBehavior is used to manage the url field for the entity that the Alias is attached to. The behavior has to be attached to an ActiveRecord class that has a language identifier. Below is an example of how it can be attached to \infoweb\pages\models\Lang, (*9)

use infoweb\alias\behaviors\AliasBehavior;

public function behaviors()
{
    return [
        'alias' => [
            'class' => AliasBehavior::className(),
            'entityType' => Page::className(),
            'entityIdField' => 'page_id'
        ],
    ];
}

The url field can be rendered in your ActiveForm view, (*10)

 // Initialize the tabs
<?= $this->render('@infoweb/alias/views/behaviors/alias/_url', [
        'form' => $form,
        'model' => $model,
        'alias' => $alias,
        'readonly' => false,
        'duplicateable' => true,
        'urlPrefix' => ''
    ]) ?>

If you want to automatically generate the alias based on the content of another field add this to its configuration:, (*11)

'data-slugable' => 'true',
'data-slug-target' => "#alias-{$model->language}-url"

Trait

The AliasRelationTrait is used to extend the entity for which you want to enable the usage of Alias. It defines custom event(s), thegetAlias relation for the model and the findByAlias method. Below is an example of how it can be attached to infoweb\pages\models\Page, (*12)

use infoweb\alias\traits\AliasRelationTrait;

class Page extends ActiveRecord
{
    use AliasRelationTrait;
}

You should also add a getUrl method to the entity (or modify it if it already exists) that uses the url field of the getAlias relation., (*13)

The Versions

04/08 2016

dev-master

9999999-dev

Alias module for Yii2

  Sources   Download

MIT

The Requires

 

alias yii2 infoweb yii2-cms-alias

03/03 2016
02/03 2016
24/02 2016
22/02 2016
10/02 2016
06/01 2016
05/01 2015
05/01 2015
11/10 2014

1.0.0

1.0.0.0

Alias module for Yii2

  Sources   Download

MIT

The Requires

 

alias yii2 infoweb yii2-cms-alias