How to set default controller for a module?

Hi,

How i can change the default controller for a module?

Problem solved:


'modules' => array(

    'facebook' => array(

        'defaultController' => 'home',

    ),

),

Put it in config file.

Ty.

Hi Prachkal…

do you mind me asking :

    'defaultController' => 'home',

what does ‘home’ mean? the path to the location of module default controller or something else?

thanks a lot.

Hi,

This is the controller name:

You can Also change the default controller in the Module Class

for example a Module Currency has CurrencyModule.php so write




class CurrencyModule extends CWebModule {

    ...

    public $defaultController='home'; // where home refers to HomeController under modules/currency/controllers

    ...

}



hello mr. i’m very new to yii, so plz help me to remove this error , i did same what you said and it’s working fine with default SiteController.

CException

homeController cannot find the requested view "index".

C:\wamp\www\yiiroot\framework\web\CController.php(878)

866 {

867 if(($viewFile=$this->getViewFile($view))!==false)

868 {

869 $output=$this->renderFile($viewFile,$data,true);

870 if($processOutput)

871 $output=$this->processOutput($output);

872 if($return)

873 return $output;

874 else

875 echo $output;

876 }

877 else

878 throw new CException(Yii::t(‘yii’,’{controller} cannot find the requested view “{view}”.’,

879 array(’{controller}’=>get_class($this), ‘{view}’=>$view)));

880 }

881

882 /**

883 * Renders a named clip with the supplied parameters.

884 * This is similar to directly accessing the {@link clips} property.

885 * The main difference is that it can take an array of named parameters

886 * which will replace the corresponding placeholders in the clip.

887 * @param string $name the name of the clip

888 * @param array $params an array of named parameters (name=>value) that should replace

889 * their corresponding placeholders in the clip

890 * @param boolean $return whether to return the clip content or echo it.

This indicates that somewhere in the HomeController, probably the actionIndex, you are trying to call


$this->render('index');

however the index.php file is not located in the moduleId/views/home/ directory. Or you are trying to call an index.php somewhere that the controller cant find it.