CWidget views

Hi! it is possible to put cwidget views in themes folder and not in protected\components\views  ?

You can set the viewPath and put your views anywhere :)

See this: http://www.yiiframew…Widget#viewPath

viewPath is read only, i can't change it.

Yes, you're right…

Try to write full path to the view file instead of it's name. If not, you can manually add setter method to the framework file.

However, editing the framework files is not a good idea.

You can also file a feature request in the google code and ask to add setter method or amy oter way of performing this task.

Quote

viewPath is read only, i can't change it.

You can change it, if you inherit a class of the widget you are using and overwritte the getViewPath() method.

example:



<?php


 /**


 * MyWidget


 *


 * @package: application.extensions.mywidget


 */


class MyWidget extends CWidget


{


	/**


	 * Returns the directory containing the view files for this widget.


	 * @return string the directory containing the view files for this widget.


	 */


	public function getViewPath()


	{


		$themeManager = Yii::app()->getThemeManager();


		


		return $themeManager->basePath.DIRECTORY_SEPARATOR.


			    'views'.DIRECTORY_SEPARATOR.strtolower(get_class($this));


	}


}


?>


usage:



<?php


Yii::import('application.extensions.mywidget.MyWidget');





$myWidget = new MyWidget;





echo $myWidget->viewPath;


?>


Returns on my test-machine:

C:\xampp\htdocs\www\yii_tests\themes\views\mywidget

greets ironic