Recommend this page to a friend! |
alternative way for work with breadcrumbs and metadata with open-graph-protocol helpers
also include NoLayoutBehavior for registration actions where layout must be skipped
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist insolita/yii2-metacrumbs "~2.0"
or add
"insolita/yii2-metacrumbs": "~1.0"
to the require section of your composer.json
file.
- register MetaCrumbsBootstrap, or manual register as singleton :
\Yii::$container->setSingleton(IBreadcrumbCollection::class,BreadCrumbs::class);
and/or
\Yii::$container->setSingleton(IMetaManager::class,MetaManager::class);
- add widget in layout
<?= \insolita\metacrumbs\widgets\CrumbWidget::widget([]) ?>
- add CrumbedControllerTrait in base controller (or in needed controllers) and register crumbs - add MetaManagerTrait in needed controllers or base controller (also in service possible)
Controller Example
class ExampleController extends Controller
{
use CrumbedControllerTrait;
use MetaManagerTrait;
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function behaviors()
{
return [
'nolayout'=>['class'=>NoLayoutBehavior::class,'actions' => ['ajax']]
// 'nolayout'=>['class'=>NoLayoutBehavior::class,'actions' => ['index','about'],'except'=>true]
];
}
public function beforeAction($action)
{
$this->registerHomeCrumb();
$this->registerIndexCrumb('??????');
if ($action->id == 'error') {
$this->registerCurrentCrumb('???????? ??????');
$this->metaManager()->canonical();
}
return parent::beforeAction($action);
}
public function actionIndex()
{
$this->metaManager()->canonical(Url::to(['example/default']));
$this->metaManager()->tag('description', 'Bla-bla-la-la-la');
$this->metaManager()->prop('og:description', 'Bla-bla-bla');
$this->metaManager()->prop('og:title', 'Bla-bla-bla');
$this->metaManager()->keywords('Some, keywords,list');
//Also
return $this->render('index');
}
public function actionView(int $id)
{
$this->crumbCollection->addCrumb(
new CrumbItem('Special crumb', Url::to(['some/page']), 20, ['target' => '_blank'])
);
$model = $this->pageFinder->findById($id);
$this->registerCurrentCrumb($model->title);
$this->metaManager()->ogMeta($model->title,Url::current([],true),$model->description,$model->cover,'article');
return $this->render('about',['model'=>$model]);
}
....
Classes of Insolita | > | How to Implement a Breadcrumbs PHP Solution in Web Page Action Controllers usingYii2 Metacrumbs | > | Download .zip .tar.gz | > | Support forum | > | Blog | > | Latest changes |
|
Groups | Applications | Files |
Groups |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Graphics | Colors, images, charts and picture formats | View top rated classes |
Design Patterns | Implementations of well known design patterns | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file, 3 directories) | ||||
tests (4 files, 2 directories) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
components (5 files) | ||||
mixins (3 files) | ||||
widgets (1 file) | ||||
MetaCrumbsBootstrap.php | Class | Class source |
Files | / | src | / | components |
File | Role | Description |
---|---|---|
BreadCrumbs.php | Class | Class source |
CrumbItem.php | Class | Class source |
IBreadcrumbCollection.php | Class | Class source |
IMetaManager.php | Class | Class source |
MetaManager.php | Class | Class source |
Files | / | src | / | mixins |
File | Role | Description |
---|---|---|
CrumbedControllerTrait.php | Class | Class source |
MetaManagerTrait.php | Class | Class source |
NoLayoutBehavior.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
config (2 files) | ||||
unit (4 files, 1 directory) | ||||
.env | Data | Auxiliary data | ||
bootstrap.php | Example | Example script | ||
unit.suite.yml | Data | Auxiliary data | ||
yii | Example | Example script |
Files | / | tests | / | config |
File | Role | Description |
---|---|---|
base.php | Aux. | Auxiliary script |
console.php | Aux. | Auxiliary script |
Files | / | tests | / | unit |
File | Role | Description | ||
---|---|---|---|---|
widgets (1 file) | ||||
bootstrap.php | Aux. | Auxiliary script | ||
BreadCrumbsTest.php | Class | Class source | ||
MetaManagerTest.php | Class | Class source | ||
NoLayoutBehaviorTest.php | Class | Class source |
Download all files: yii2-metacrumbs.tar.gz yii2-metacrumbs.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file, 3 directories) | ||||
tests (4 files, 2 directories) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
components (5 files) | ||||
mixins (3 files) | ||||
widgets (1 file) | ||||
MetaCrumbsBootstrap.php | Class | Class source |
Files | / | src | / | components |
File | Role | Description |
---|---|---|
BreadCrumbs.php | Class | Class source |
CrumbItem.php | Class | Class source |
IBreadcrumbCollection.php | Class | Class source |
IMetaManager.php | Class | Class source |
MetaManager.php | Class | Class source |
Files | / | src | / | mixins |
File | Role | Description |
---|---|---|
CrumbedControllerTrait.php | Class | Class source |
MetaManagerTrait.php | Class | Class source |
NoLayoutBehavior.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
config (2 files) | ||||
unit (4 files, 1 directory) | ||||
.env | Data | Auxiliary data | ||
bootstrap.php | Example | Example script | ||
unit.suite.yml | Data | Auxiliary data | ||
yii | Example | Example script |
Files | / | tests | / | config |
File | Role | Description |
---|---|---|
base.php | Aux. | Auxiliary script |
console.php | Aux. | Auxiliary script |
Files | / | tests | / | unit |
File | Role | Description | ||
---|---|---|---|---|
widgets (1 file) | ||||
bootstrap.php | Aux. | Auxiliary script | ||
BreadCrumbsTest.php | Class | Class source | ||
MetaManagerTest.php | Class | Class source | ||
NoLayoutBehaviorTest.php | Class | Class source |
Download all files: yii2-metacrumbs.tar.gz yii2-metacrumbs.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|