Skip to content

Instantly share code, notes, and snippets.

@rootbear
Last active December 22, 2015 11:59
Show Gist options
  • Save rootbear/6469750 to your computer and use it in GitHub Desktop.
Save rootbear/6469750 to your computer and use it in GitHub Desktop.
Access to other modules
<?php
//config 3rd party component
'components'=>array(
...
'mailer'=>array(
'class'=>'application.extensions.mailer.EMailer',
'Mailer'=>'smtp',
'Host'=>'yourhost',
'SMTPAuth'=>true,
'Username'=>'smtpuser',
'Password'=>'smtppass',
),
),
?>
<?php
//To access a different module or a model within a different module, use
Yii::app()->getModule('moduleName');
//You can then use models from that module in the usual way.
//within module
echo Yii::app()->controller->module->property_name;
//in module file
public function property_name(){
return 'value_of_property'
}
echo Yii::app()->controller->id; //or
echo Yii::app()->getController()->getId();
//$this->id here $this refers to current controller
To get method/action name
echo Yii::app()->controller->action->id;
//You can get action name in controller
echo $this->action->id;
//To get module name
echo Yii::app()->controller->module->id;
$this->module->id
?>
<?php
//in config
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'user/passwordreset/t/<someString:\w+>' => 'user/passwordReset/'
),
//the URL : user/passwordreset/t/asdagfasgas
//Inside UserController have a function
actionPasswordReset($someString){
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment