This is the correct answer
This is the correct answer
Hei guys!
I’ve create “admin” module and in AdminModule.php i’ve:
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;
}
But breadcrumbs "home" continue to point to my site home page. The debug toolbar show me:
array
(
'class' => 'CWidgetFactory'
'enableSkin' => false
'widgets' => array
(
'CBreadcrumbs' => array
(
'homeLink' => '<a href=\"/dev.php/admin\">Home</a>'
)
)
'skinnableWidgets' => null
'skinPath' => null
'behaviors' => array()
)
What’s wrong?
good!!!
谢谢
Why make this so complicated? Just override the homeUrl property from inside CWebModule::init(). This applies the change wherever Yii::app()->homeUrl is called, which seems more in line with your use case.
protected function init()
{
...
Yii::app()->homeUrl = '/module';
...
}
I had the same issue.
My solution is to add a home link property to the module:
<?php
class MyModule extends CWebModule
{
public $moduleLink = array('/mymodule'); // route to module
public $moduleLinkInner = 'My Module'; // breadcrumb title
....
}
?>
And then in protected/views/layouts/main.php:
<?php
if(Yii::app()->controller->module!==null) {
// Current controller belongs to a module
$module = Yii::app()->controller->module;
$this->breadcrumbs = array_merge(
// Prepend module breadcrumb
array(
$module->moduleLinkInner => $module->moduleLink
),
$this->breadcrumbs
);
}
$this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
)); ?><!-- breadcrumbs -->
This lets you keep your module views’ breadcrumbs as they are (i.e. as generated by gii).
Regards,
Joachim
It worked for me. Thanks.