【发布时间】:2014-09-02 02:32:59
【问题描述】:
当我使用 $this->widget('someWidget',array() } 时,我需要将其放入/protected/components 文件夹中。
如果我想在/protected/anotherFolder 中添加一些小部件怎么办?
我可以设置一些东西让 $this->widget() 函数找到另一个文件夹而不更改 $this->widget() 中的参数吗?
【问题讨论】:
当我使用 $this->widget('someWidget',array() } 时,我需要将其放入/protected/components 文件夹中。
如果我想在/protected/anotherFolder 中添加一些小部件怎么办?
我可以设置一些东西让 $this->widget() 函数找到另一个文件夹而不更改 $this->widget() 中的参数吗?
【问题讨论】:
如果你想把它放在另一个文件夹中,那么你必须给它完整的路径才能像在控制器中一样使用它:
$this->widget('application.anotherFolder.someWidgetFolder.someWidgetClass' , $params);
或者你可以在 config/main 中创建一个别名
Yii::setPathOfAlias('anotherFolder', dirname(__FILE__) . '/../anotherFolder/someWidgetFolder');
让它变得像
$this->widget('anotherFolder.someWidgetClass' , $params);
【讨论】:
你可以在配置中这样做:
return array(
'aliases' => array(
'bootstrap' => 'ext.bootstrap',
),
);
【讨论】: