Yii Framework Forum: Breadcrumbs for a module needs home url changed to module home url - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Breadcrumbs for a module needs home url changed to module home url Rate Topic: -----

#1 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 23 January 2011 - 11:55 AM

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?
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 23 January 2011 - 02:09 PM

http://www.yiiframew...homeLink-detail
0

#3 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 23 January 2011 - 02:24 PM

Can I set this per module?
0

#4 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 23 January 2011 - 04:04 PM

Yeah man, just define the breadcrumb widget in your module layout file.
0

#5 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 02:06 AM

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?
0

#6 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 24 January 2011 - 02:26 AM

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.
0

#7 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 02:49 AM

I've added this and it's not recognized by the breadcrumbs



class AdminModule extends CWebModule {
    public $homeUrl="/admin/";

}

0

#8 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 24 January 2011 - 03:03 AM

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;

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#9 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 24 January 2011 - 03:16 AM

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
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
1

#10 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 03:16 AM

I've tried to put this in the theme's main.php file
per like this: http://www.yiiframew...idgets-globally

<?php $this->widget('zii.widgets.CBreadcrumbs', array(
    'homeLink'=>'/admin/',
));?>



but doesn't worked out either
0

#11 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 03:17 AM

View PostGustavo, on 24 January 2011 - 03:16 AM, said:

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.
0

#12 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 24 January 2011 - 03:20 AM

edit the default homeLink in framework/zii/widgets/CBreadcrumbs.php and you can do that
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#13 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 03:31 AM

I've found a documentation node that says how to customize widgets per theme
it's described here:
http://www.yiiframew...idgets-globally

but that doesn't work out for me, what I am doing wrong?
0

#14 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 24 January 2011 - 03:33 AM

how can we know if you dont post your code?
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#15 User is offline   Pentium10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 174
  • Joined: 10-December 10

Posted 24 January 2011 - 03:35 AM

it's in post #10 as mentioned earlier
0

#16 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 24 January 2011 - 03:41 AM

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/',
                ),
            ),
        ),
    ),
);

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
1

#17 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 24 January 2011 - 04:10 AM

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)
1

#18 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 24 January 2011 - 08:45 AM

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;
	}

1

#19 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 24 January 2011 - 10:47 AM

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.
0

#20 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 492
  • Joined: 21-May 11
  • Location:India

Posted 21 June 2011 - 01:26 AM

View PostGustavo, on 24 January 2011 - 03:16 AM, said:

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



-- thnkx
Thanks,
Kiran Sharma.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users