Best place for Widgets and their view scripts

This topic contains two questions.

1. What is the best place for widgets in a Yii project?

Some sources say it’s best to place a widget file directly under [font=“Courier New”]protected/components[/font], while others say it’s best to place them under [font=“Courier New”]protected/extensions/widgets[/font].

2. What is the best place and naming-convention for the view scripts belonging to the widget?

Let’s say I have my widgets under [font=“Courier New”]protected/extensions/widgets[/font], like so:




protected/

    extensions/

        widgets/

            views/

                MyCalendar.php        # view script for the MyCalendar widget

                MyMenu.php            # view script for the MyMenu widget

            MyCalendar.php

            MyMenu.php



Would this be the best way?

Is a question of convention, I am not sure there is a "best".

I use protected/component, in a project there were too much components and we moved all to protected/widgets.

The only difference is that if you use a directory imported, you can use $this->widget without the full alias path, that can be confortable

Thanks zaccaria.

I guess my question should have been Is there a Yii convention about placement and naming of widget class files and view scripts?.

From your answer however I understand there is no convention on this, correct me if I’m wrong.

The path alias isn’t a problem either I am using the following code at the top of my [font=“Courier New”]protected/config/main.php[/font] file.


Yii::setPathOfAlias('widgets', dirname(__FILE__) . '/../extensions/widgets');

Which makes it possible for me to insert widgets in a view script like this:


<?php $this->widget('widgets.MyMenu'); ?>

Hi,

i have an question, how to address the widget.

My widget is located at protected/widget/MyWidget.

At the main.php (the main layout file) I’m trying to load/open the widget in the following way:


$this->widget('application.widgets.MyWidget');

But this does not work. An Error occurs. Something like "alias is not valid"

…but i think application is the path to “protected”. Is’n it?

Where is the error coming from?

maybe this typo (missing "s")?