Controllers are not intended to be 'utility'  I think you're going
about things the wrong way.  Components are intended to be 'utility
classes' and components can have components.  Realistically the only
time you should be manually constructing a controller is for unit
testing.  Outside of that you are probably doing things the wrong
way.  Plus constructing a controller isn't enough to build all the
classes it uses.  There are several callbacks that need to be
triggered as well.

-Mark

On Jan 19, 3:25 pm, gerhardsletten <[email protected]> wrote:
> Writing an app where I was planing to move all email delivering in one
> controller. When I try to load this "Utility" controller in a function
> from another controller. App::import fail to load Email component in
> this controller
>
> Controller 1:
> <code>
> function send_message() {
> ...
> App::import('Controller', 'Main');
> $main = new MainController;
> $main->simplemail($to, $subject, $body);}
>
> </code>
>
> Utility controller:
> <code>
> class MainController extends AppController {
>
> var $name = 'Main';
> var $components = array('Email');
> var $uses = null;
> ...
> function simplemail($to, $subject, $body) {
>                 $mail_settings = Configure::read('Mail');
>                 $this->Email->from    = $mail_settings['from_name'] . ' <' .
> $mail_settings['from_mail'] . '>';
>                 $this->Email->to      = $to;
>                 $this->Email->subject = $subject;
>                 debug($this->Email);
>                 //$this->Email->send($body);
>
>         }
>
> </code>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to