Localized view files problem

I work on an application, in wich, you can switch from one language to another, and the controller loads the localized view file from the desired directory.




views/

  site/

    hu/

      index.php

    en/

      index.php



It is working fine, until I remove the index.php view file from the views/site/ directory. The index.php is used by the actionIndex() method of the SiteController (in my case). When I delete this file, I got the "SiteController cannot find the requested view "index"." message. If I put even a total empty "index.php" under the views/site/ directory, it works fine: the controller loads the "views/site/hu/index.php" or the "views/site/en/index.php" depend on the application language.

Is this some kind of bug, or I do something wrong? Any idea?

Hi!

I had the same problem.

To resolve you should override the CController’s “resolveViewFile” method in your Controller class (or any parent class)

like this (Just the last line modified):




    public function resolveViewFile($viewName,$viewPath,$basePath,$moduleViewPath=null) {

        if(empty($viewName))

                return false;


        if($moduleViewPath===null)

                $moduleViewPath=$basePath;


        if(($renderer=Yii::app()->getViewRenderer())!==null)

                $extension=$renderer->fileExtension;

        else

                $extension='.php';

        if($viewName[0]==='/')

        {

                if(strncmp($viewName,'//',2)===0)

                        $viewFile=$basePath.$viewName;

                else

                        $viewFile=$moduleViewPath.$viewName;

        }

        else if(strpos($viewName,'.'))

                $viewFile=Yii::getPathOfAlias($viewName);

        else

                $viewFile=$viewPath.DIRECTORY_SEPARATOR.$viewName;


        if(is_file($viewFile.$extension))

                return Yii::app()->findLocalizedFile($viewFile.$extension);

        else if($extension!=='.php' && is_file($viewFile.'.php'))

                return Yii::app()->findLocalizedFile($viewFile.'.php');

        else

                return Yii::app()->findLocalizedFile($viewFile.$extension);

    }