load a view file from a completely different directory

How can i make this work:


$this->renderPartial($view_path . '/core/groups/groups_index', array(), true)

I am currently in a certain controller and inside i am trying to load a view from a completly different directory. The code above does not work and throws an exception that the view file was not found:


admin_group_form__core cannot find the requested view "C:\wamp\www\all_mighty_yii\Protected\modules\admin\views\default/core/groups/groups_index".

I do want to allow the option to load the view from a different directory.

Any help and tips will be appreciated.

maybe this could help

http://www.yiiframework.com/doc/api/CController#resolveViewFile-detail

Wouldn’t help much. I know the path the view resides in, I want to load it with renderpartial but i think the system looks up the view under the current used controller.

Do yo test using ‘/’ at the beginnin of the path?


$this->renderPartial('/'.$view_path . '/core/groups/groups_index', array(), true)

I’m not shure if this works, but testing doesn’t hurt anybody…

You can try to override getViewPath() method in your controller.

Put follow code in your controller.




  public function getViewPath()

  {

    return '/your/view/path';

  }



This will change your controller read view file from /your/view/path directory.

Pol that didn’t work, But light idea did work. But what happens if you the function not inside a controller?

CController use getViewPath() to determine where is view file. Your controller extends from CController and has this default method. Child class can override method comes from parent. And make other methods ( render(), renderPartial(),… ) use Child’s new method.

If you move the function outside your controller, your controller will use old function comes from parent.

If you want to switch view file path between yii default path and your path. Maybe you can use a object variable to select, which is like the following code.

Insert a new variable in your controller class.




  public $viewPathSelector;



and change the getViewPath().




  public function getViewPath()

  {

    switch($this->viewPathSelector) 

    {

      case 1:

        $result='/your/view/path';

        break;      

      default:

        $result=parent::getViewPath();

        break;

    }

    return $result;

  }



now you can select what view file path your controller action use.

following code is inside your controller.




  public function actionIndex()

  {

	$this->viewPathSelector=0; //will use yii default path

	$this->render('index');

	$this->viewPathSelector=1; //will use '/your/view/path'

	$this->renderPartial('your_view');


  }



Did you try this




$this->renderPartial('application.views.core.groups.groups_index',

          array(),true);



This will work from version 1.0.2 as seen in documentation: CController::getViewFile method