1. Go to this page and download the library: Download inblank/yii2-seobility library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inblank / yii2-seobility example snippets
use inblank\seobility\SeobilityBehavior;
/**
* ...
*/
class Model extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
SeobilityBehavior::className(),
];
}
}
$model = Model::findOne(1);
// set data by the behavior method
$model->setSeobility([
'title' => 'SEO title for model',
'keywords' => 'model, seo, keywords, yii2',
'description' => 'Simple model with SEO data'
]);
// ... or by direct access
$model->seobility = [
'title' => 'SEO title for model',
'keywords' => 'model, seo, keywords, yii2',
'description' => 'Simple model with SEO data'
];
// not necessarily set all field for SEO data
// code below set only `title` field
$model->seobility = [
'title' => 'Chnaged SEO title',
];
// need to save model to store all setting SEO data
$model->save();
$model = Model::findOne(1);
// setting a data with condition is only possible through the method of behavior
// set SEO data for condition=1
$model->setSeobility([
'title' => 'Another SEO title',
'keywords' => 'model, seo, keywords, yii2',
'description' => 'This description is different'
], 1);
// need to save model to store all setting SEO data
$model->save();
$model = Model::findOne(1);
// getting default data through the method of behavior
$seo = $model->getSeobility();
// ... or by direct access
$seo = $model->seobility;
$model = Model::findOne(1);
// getting data with condition is only possible through the method of behavior
$seo = $model->getSeobility(1);
// not get the default data if data with `condition=1` not found
// i.e. if the data with `condition=1` will not be found, it returns
// an array with empty values
$seo = $model->getSeobility(1, false);
// get data with `condition=2` if not found data with `condition=1`
// and if not found data with `condition=1` will return an array with empty values
$seo = $model->getSeobility(1, true, 2);
$model = Model::findOne(1);
// getting all data
$seo = $model->getAllSeobility();
$model = Model::findOne(1);
// remove default data
$seo = $model->deleteSeobility();
$model = Model::findOne(1);
// remove data with condition=1
$seo = $model->deleteSeobility(1);
$model = Model::findOne(1);
// remove ALL model's SEO data
$seo = $model->deleteAllSeobility();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.