How Controller Actions Know Where To Find View File?

Hello, I am following “Yii Rapid Application Development” tutorial (eBook).

In “Creating a Mobile View Widget” section I did following:

Created new directory /protected/extensions/mobile/views

Inside /mobile/ dir. I created file ‘ListView’, this file has the init() and run() functions.

Inside /views/ dir. I created ‘body’, ‘_mview’ and ‘mobile_index’ files.

Then I modified function ‘actionIndex’ inside controller file.

The logic in this function is, if user is using “mobile” version, the $this->render should use ‘mobile_index’ view file, located in /protected/extensions/mobile, else use ‘index’ file inside /protected/views/ directory, and this works.

I understand that normally the $this->render function (inside controller) will look for view file in /protected/views/model/ directory, but what will happened if $this->render function will get view file name that is located in different directory?

Here is the controller action function that makes the decision on which view file to render.


public function actionIndex()

{

$view = 'index';

$dataProvider=new

CActiveDataProvider('Book');

if (Yii::app()->user->getState('mobile')) {

$view = 'mobile_index';

}

$this->render($view,array(

'dataProvider'=>$dataProvider,

));

}

For me onece ‘mobile’ is detected I get error: cant locate ‘mobile_index’ view file.

Any thoughts?

Thanks.