crowhill
crowhill

Reputation: 2558

using a yii widget from a view

This seems like it should be dead simple, but I'm struggling.

So, the following line works great when I have it in a layout. That is, from "/protected/views/layouts/baselayout.php" the line:

$this->widget('BuildingList');

Works exactly like it should. It creates a building list.

However, when the same line of code is used in a view, it fails. That is, from "/protected/views/rooms/update.php" I get

Include(/Var/Www/Html/Yii/Framework/Zii/Widgets/CWidget.Php): Failed To Open Stream: No Such File Or Directory

For what it's worth, CWidget.php definitely isn't in "/zii/widgets". It's in "/framework/web/widgets"

But somehow Yii knows where to find the CWidget.php from the layout and not the view

Upvotes: 2

Views: 81

Answers (1)

rodrigovr
rodrigovr

Reputation: 454

Try using the widget by its full name.

If it is in /protected/components, them:

$this->widget('application.components.BuildingList');

You can also add it to the 'import' section in your config file, like this:

'import'=> [ 
             'application.models.*', 
             'application.components.*', 
             'ext.*' 
           ],

Upvotes: 0

Related Questions