pentium10
(Hexagonhu)
January 23, 2011, 4:55pm
1
I have this code:
$this->breadcrumbs=array(
'Developers'=>array(Yii::t('app', 'index')),
Yii::t('app', 'Manage'),
);
This creates a breadcrum like this:
Home » Developers » Manage
Where Home links to site home, and I want to link to the module home.
Developers links to the correct url.
What should I change?
GSTAR
(Omzy83)
January 23, 2011, 7:09pm
2
pentium10
(Hexagonhu)
January 23, 2011, 7:24pm
3
Can I set this per module?
GSTAR
(Omzy83)
January 23, 2011, 9:04pm
4
Yeah man, just define the breadcrumb widget in your module layout file.
pentium10
(Hexagonhu)
January 24, 2011, 7:06am
5
I know how to use the widget, but I don’t know how to set in one place the homeUrl of the breadcrumb widget.
Could you please show me how can I define the homeUrl for a given module?
zaccaria
(Matteo Falsitta)
January 24, 2011, 7:26am
6
There are many options.
You can create a new template for the module, and defining in this new template the widget, so you will have complete control on all properties.
You can add a new property on Controller.php (located under protected/components):
public $homeUrl="/"
And use this for configure the home url in the layout/main.php.
In the controllers of the module you can set the home url to be the home of the module.
pentium10
(Hexagonhu)
January 24, 2011, 7:49am
7
I’ve added this and it’s not recognized by the breadcrumbs
class AdminModule extends CWebModule {
public $homeUrl="/admin/";
}
gusnips
(Gustavo)
January 24, 2011, 8:03am
8
in the layout you can access only properties defined in the controller, not included the variable passed to the view file
and you use it like this in the layout file:
echo $this->homeUrl;
gusnips
(Gustavo)
January 24, 2011, 8:16am
9
in your main layout
if(count($this->breadcrumbs))
$this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'homeLink'=>(isset($this->homeUrl) ? $this->homeUrl : '/')
));
you can find more options here
pentium10
(Hexagonhu)
January 24, 2011, 8:16am
10
I’ve tried to put this in the theme’s main.php file
per like this: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming#customizing-widgets-globally
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'homeLink'=>'/admin/',
));?>
but doesn’t worked out either
pentium10
(Hexagonhu)
January 24, 2011, 8:17am
11
if(count($this->breadcrumbs))
$this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
'homeLink'=>(isset($this->homeUrl) ? $this->homeUrl : '/')
));
you can find more options here
I want to set globally, not by editing each file where I’ve used this.
gusnips
(Gustavo)
January 24, 2011, 8:20am
12
edit the default homeLink in framework/zii/widgets/CBreadcrumbs.php and you can do that
pentium10
(Hexagonhu)
January 24, 2011, 8:31am
13
I’ve found a documentation node that says how to customize widgets per theme
it’s described here:
http://www.yiiframework.com/doc/guide/1.1/en/topics.theming#customizing-widgets-globally
but that doesn’t work out for me, what I am doing wrong?
gusnips
(Gustavo)
January 24, 2011, 8:33am
14
how can we know if you dont post your code?
pentium10
(Hexagonhu)
January 24, 2011, 8:35am
15
it’s in post #10 as mentioned earlier
gusnips
(Gustavo)
January 24, 2011, 8:41am
16
as its explained in the link you sent, you must change in the main config file (probably configs/main.php)
something like:
return array(
//other config
'components'=>array(
//other components
'widgetFactory'=>array(
'widgets'=>array(
'CBreadcrumbs'=>array(
'homeLink'=>'/admin/',
),
),
),
),
);
zaccaria
(Matteo Falsitta)
January 24, 2011, 9:10am
17
Nice idea, Gustavo.
Maybe in adminModule is possible to do something like:
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
Yii::app()->widgetFactory->widgets['CBreadcrumbs']=array( 'homeLink'=>array('/admin'));
return true;
}
else
return false;
}
I never tried it before, but according to the doc looks possible.
Let us know if it works.
Also is better to write array(’/admin’) instead of ‘/admin’, in this case the base url will be added if needed (and will work even in case of routig with parameters)
zaccaria
(Matteo Falsitta)
January 24, 2011, 1:45pm
18
The correct way is:
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
Yii::app()->widgetFactory->widgets['CBreadcrumbs']=array( 'homeLink'=>CHtml::link('Home', array('/admin')));
return true;
}
else
return false;
}
GSTAR
(Omzy83)
January 24, 2011, 3:47pm
19
Not sure if this helps, but perhaps put a Controller.php in your module’s ‘components’ folder and define a public $breadcrumbs object in there? Your module’s controllers should automatically extend from this controller class.