How can I change directory name in views directory

I have controller class name ‘MyFoo’. Right now Iam storing views in folder with same name of view folder. My view folder name is ‘myFoo’. Can I change my view’s folder name as ‘barViews’ and there should be no errors from controller and controller finds ‘views’ in that folder.

In simple, I don’t want to be the same name of both views folder and Controller class.

Can some one guide me in this regards.

Thanks in advance

In your controller overide getViewPath() so it returns the new path of your view files

if the barViews is under the protected/view folder you can even use

$this->render(’/barViews/index’,…) instead of $this->render(‘index’,…)

The Yii rendering mechanism basically works these options:

  1. $this->render("foo"); will look for foo.php in a folder having the same name as the controller under views directory.

  2. $this->render("application.mypath.to.viewfile"); will look for mypath/to/viewfile.php

  3. $this->render("/mypath"); placing a forward slash before the view path, will explicitly look for the given path.

For more info look at : CController.php line 602

I hope this helps.

Gevik,

This post is extremely helpful! I wish I could have found this information on the ‘views’ page of the yii documentation. Would have saved a bit of time for me and I am sure others as well! Thank you for contributing to the forum and therefore the entire Yii Community.