Download the PHP package inblank/yii2-seobility without Composer
On this page you can find all versions of the php package inblank/yii2-seobility. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-seobility
Behavior for Yii2 to manage SEO data for ActiveRecord
Русская версия этого документа доступна здесь.
Behavior yii2-seobility
for Yii2 allows you to manage SEO data for ActiveRecord models. For each model,
you can store multiple records with SEO data and select according to the condition. If data with the condition
not found, then will returned the default data, and if them not, will returned the data with empty values.
Each SEO data entry contains the fields: title
, keywords
and description
.
Installation
The preferred way to install this extension is through composer.
Navigate to the project folder and run the console command:
or add:
to the require
section of your composer.json
file.
Configuring
Database
To storing SEO data the behavior uses an ActiveRecord model's database connection. Behavior does not create and does not check for required tables. Tables must be created before using.
The name of the table to store and retrieve data, the behavior has on the basis of the table name of
the ActiveRecord model to which is attached. The name is created by adding the suffix _seo
to the
table name of the ActiveRecord model. To get the table name of the model the model uses the
method ActiveRecord::tableName()
Examples:
- If the model uses a table
model
, the behaviour will use the tablemodel_seo
.- If the model uses a table
{{%model}}
, the behaviour will use the table{{%model_seo}}
.
To create a table use the following SQL query, replacing model_seo
by required table name:
The query uses the MySQL syntax
Model
To use a behavior just attach it to the ActiveRecord model as specified in the Yii2 documentation
If you correctly created a table to store the SEO data, configuring is complete.
Usage
After successful configuration, you can use behavior methods to manage SEO data of ActiveRecord models.
Setting default SEO data
Default SEO data have condition=0
To setting default SEO data:
After saving the model, the default SEO data will contain defined values and these will be available at any time.
Note: If the model has not passed validation and was not saved SEO data will not be saved too.
Setting SEO data with condition
To setting SEO data with condition:
Note: If the model has not passed validation and was not saved SEO data will not be saved too.
Getting default SEO data
To getting default SEO data:
After getting the data, the variable $seo
will contain an array with keys title
, keywords
and description
.
Data will be obtained even if they were not specified. In this case, all array fields will contain empty value.
Getting SEO data with condition
To getting SEO data with condition:
Will be obtained SEO data with condition=1
, and if no such data will be getting
the default SEO data, or empty if no default data.
Through the method parameters, you can specify what data to obtain if the requested data is not found.
Getting all SEO data
To getting all SEO data:
After getting the data, the variable $seo
will contain an array with all the SEO data.
Indices of elements in the array are the values of the condition
.
Remove default SEO data
To remove default SEO data:
Attention: Be careful, the removal happens immediately and does not require
$model->save()
method. Removed data cannot be restore.
Remove SEO data with condition
To remove SEO data with condition:
Attention: Be careful, the removal happens immediately and does not require
$model->save()
method. Removed data cannot be restore.
Remove all SEO data for model
To remove all SEO data for model:
Attention: Be careful, the removal happens immediately and does not require
$model->save()
method. Removed data cannot be restore.