Permalink
Browse files

added breadcrumbs widget

  • Loading branch information...
1 parent 32ca1c6 commit ac1d69a14b36d7ad7976b537d2f35306d043dfc0 anton committed Nov 4, 2012
@@ -0,0 +1,33 @@
+<?php
+Yii::import('zii.widgets.CBreadcrumbs');
+
+class AmEntityBreadcrumbs extends CBreadcrumbs
+{
+ public function init()
+ {
+ $this->links = $this->generate();
+ }
+
+ protected function generate()
+ {
+ $controller = $this->controller;
+ $entity = $controller->getEntity();
+ if ('update' === $controller->action->id) {
+ $breadcrumbs[] = AppManagerModule::t('Update');
+ $breadcrumbs[$entity->getTitle()] = array('view', 'id' => $entity->getId());
+ } else {
+ $breadcrumbs[] = $entity->getTitle();
+ }
+ $model = $controller->getModel();
+ while ($entity = $entity->getParent()) {
+ if ($entity->getId() === $model->getId()) {
+ $url = array($controller->defaultAction);
+ } else {
+ $action = $entity->canList() ? 'list' : 'view';
+ $url = array($action, 'id' => $entity->getId());
+ }
+ $breadcrumbs[$entity->getTitle()] = $url;
+ }
+ return array_reverse($breadcrumbs);
+ }
+}
@@ -15,10 +15,6 @@ protected function createModel()
public function actionSettings()
{
$this->baseEntity = $this->getEntity();
- $this->setBreadcrumbs(array(
- $this->getEntity()->getTitle() => array($this->defaultAction),
- AppManagerModule::t('Settings'),
- ));
$this->actionUpdate($this->getEntity()->getId());
}
View
@@ -1,8 +1,3 @@
-<?php
-$this->breadcrumbs=array(
- $entity->title,
-);
-?>
<?php
$confirm = 'function(){if(!confirm('
. CJavaScript::encode(AppManagerModule::t('Are you sure?'))
View
@@ -1,8 +1,3 @@
-<?php
-$this->breadcrumbs=array(
- $entity->title,
-);
-?>
<?php
$confirm = 'function(){if(!confirm('
. CJavaScript::encode(AppManagerModule::t('Are you sure?'))
View
@@ -1,9 +1,8 @@
<?php $this->beginContent('/layouts/main'); ?>
<div class="menu-sections">
<?php if(isset($this->breadcrumbs)):?>
- <?php $this->widget('zii.widgets.CBreadcrumbs', array(
+ <?php $this->widget('AmWidgets.AmEntityBreadcrumbs', array(
'homeLink' => CHtml::link(AppManagerModule::t('Home'), array('/appManager')),
- 'links' => $this->breadcrumbs,
)); ?><!-- breadcrumbs -->
<?php endif?>
<?php $this->widget('zii.widgets.CMenu', array('items'=>$this->getMenu())); ?>

0 comments on commit ac1d69a

Please sign in to comment.