diff --git a/README.md b/README.md index b939072..ccd9163 100644 --- a/README.md +++ b/README.md @@ -80,16 +80,6 @@ Download the [latest version](https://github.com/cornernote/yii-email-module/arc ## Configuration -If you installed with composer, you should set an alias to your `vendor` folder in your yii configuration: - -```php -return array( - 'aliases' => array( - 'vendor' => '/path/to/vendor', - ), -); -``` - Add yii-email-module to the `modules` in your yii configuration: ```php @@ -97,9 +87,7 @@ return array( 'modules' => array( 'email' => array( // path to the EmailModule class - 'class' => 'vendor.cornernote.yii-email-module.email.EmailModule', - // if you downloaded into modules - //'class' => 'application.modules.email.EmailModule', + 'class' => '/path/to/vendor/cornernote/yii-email-module/email/EmailModule', // add a list of users who can access the email module 'adminUsers' => array('admin'), @@ -199,11 +187,13 @@ return array( Yii::app()->emailManager->email('user@dom.ain', 'test email', 'Hello World!'); ``` + ### Using Templates To send more complex emails you will need to use Email Templates. -### Component + +#### Component Create a new component in `components/Email.php`: @@ -238,7 +228,8 @@ class Email { } ``` -### PHP Templates + +#### PHP Templates Subject `views/emails/example/subject.php`: ```php @@ -255,7 +246,8 @@ Message `views/emails/example/message.php`: awesome email!'; ``` -### DB Templates + +#### DB Templates Subject ``` @@ -273,7 +265,7 @@ Here is an awesome email! ``` -### Sending the Email +#### Sending the Email Now you can send an email like this: @@ -282,6 +274,7 @@ $user = User::model()->findByPk(123); Email::sendUserWelcome($user); ``` + ### Sending Spooled Emails You can send the spooled emails using the yiic command: @@ -290,6 +283,7 @@ You can send the spooled emails using the yiic command: yiic emailSpool ``` + ### Automatically Sending Setup [lockrun](https://github.com/pushcx/lockrun) for overlap protection. This allows us to setup a cron job that will run every minute, with no risk of a new process starting if an existing process is running. diff --git a/email/EmailModule.php b/email/EmailModule.php index 4537186..a8eee24 100644 --- a/email/EmailModule.php +++ b/email/EmailModule.php @@ -115,24 +115,8 @@ public function init() if (empty($this->modelMap[$method][$name])) $this->modelMap[$method][$name] = $options; - // when in web application - if (Yii::app() instanceof CWebApplication) { - // and in this module - $route = explode('/', Yii::app()->urlManager->parseUrl(Yii::app()->request)); - if ($route[0] == $this->id) { - // setup yiiStrap components - if ($this->yiiStrapPath) { - Yii::setPathOfAlias('bootstrap', realpath($this->yiiStrapPath)); - Yii::import('bootstrap.helpers.TbHtml'); - Yii::app()->setComponents(array( - 'bootstrap' => array( - 'class' => 'bootstrap.components.TbApi', - ), - ), false); - } - } - } - + // init yiiStrap + $this->initYiiStrap(); } /** @@ -192,4 +176,35 @@ public function setAssetsUrl($value) $this->_assetsUrl = $value; } + /** + * Setup yiiStrap, works even if YiiBooster is used in main app. + */ + public function initYiiStrap() + { + // check that we are in a web application + if (!(Yii::app() instanceof CWebApplication)) + return; + // and in this module + $route = explode('/', Yii::app()->urlManager->parseUrl(Yii::app()->request)); + if ($route[0] != $this->id) + return; + // and yiiStrap is not configured + if (Yii::getPathOfAlias('bootstrap') && file_exists(Yii::getPathOfAlias('bootstrap.helpers') . '/TbHtml.php')) + return; + // try to guess yiiStrapPath + if ($this->yiiStrapPath === null) + $this->yiiStrapPath = Yii::getPathOfAlias('vendor.crisu83.yiistrap'); + // check for valid path + if (!realpath($this->yiiStrapPath)) + return; + // setup yiiStrap components + Yii::setPathOfAlias('bootstrap', realpath($this->yiiStrapPath)); + Yii::import('bootstrap.helpers.TbHtml'); + Yii::app()->setComponents(array( + 'bootstrap' => array( + 'class' => 'bootstrap.components.TbApi', + ), + ), false); + } + }