Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:47:08+00:00 2026-05-25T02:47:08+00:00

I have a component that connects to a remove data base for several different

  • 0

I have a component that connects to a remove data base for several different reasons. However the remote data base is not guaranteed up, so in case it is down I want to send an email alerting someone that it failed.

Here is an example

App::import('Vendor', 'remote_connection_pdo');

class RemoteComponent extends Object 
{
    public $components = array('Email');

    private function remote_connection_failed($data)
    {
        //set info about what was processing when connection failed
        $this->set(compact('data'));

        $this->Email->to = 'team@example.com';
        $this->Email->subject = 'Remote Connection Failed';
        $this->Email->template = 'remote_connect_failure';
        $this->Email->sendAs = 'html';

        $this->Email->send();
    }

    public function doSomething($data)
    {
        try
        {
            $pdo = new RemoteConnectionPDO(RemoteConnectionPDO::getConnection());
        }
        catch(PDOException $e)
        {
            $conn_fail_data = array(
                'While Processing'  => 'Doing something',
                'Other Info'        => $data['Other']['info'],
                'foo'               => 'bar',
            );
            $this->remote_connection_failed($conn_fail_data);

            return false;
        }

        //do something
        //...
        return true;
    }
}

The problem is the component class deosn’t have the set() method like the controller class does. So I get this error:

Fatal error: Call to undefined method RemoteComponent::set() in
/var/www/app/controllers/components/remote.php on line 19

I need to set the data for the view the email is going to use (not the view rendered to the user)

I want to handle this internally in the component because many controllers may use this component for different reasons and this component handles all the connections to the remote db.

So any ideas on what would be ideal for this situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:47:09+00:00Added an answer on May 25, 2026 at 2:47 am

    I’m not sure if this is the best way to proceed by I usually create a method in the AppController:

    protected function __sendMail($from,$to,$bcc,$subject,$replyto,$template,$attachments = array(),$headers = array()){
            // SMTP Options
            $this->Email->smtpOptions = array(
                'port'=>MAIL_PORT, 
                'timeout'=>'30',
                'host' => MAIL_HOST,
                'username'=>SENDER_MAIL,
                'password'=>SENDER_PASS
            );
    
            // Set delivery method
            $this->Email->delivery = 'smtp';
            $this->Email->SMTPAuth = true;
            $this->Email->SMTPSecure = 'tls';
            $this->Email->charset  = 'UTF-8';
            $this->Email->to = $to;
            $this->Email->bcc = $bcc;
            $this->Email->subject = $subject;
            $this->Email->replyTo = $replyto;
            $this->Email->from = $from;
            $this->Email->template = $template;
            $this->Email->header($headers); 
    
            //Send as 'html', 'text' or 'both' (default is 'text')
            $this->Email->sendAs = 'both';
    
            $this->Email->attachments = $attachments;
    
            // Do not pass any args to send()
            $this->Email->send();
    
            // Check for SMTP errors.
            $this->set('smtp_errors', $this->Email->smtpError);
    
        }
    

    I put it in the AppController because I use it in different controllers. So in your case, id save the reference of the Controller (or pass it as an argument), something like this

    class RemoteComponent extends Object 
    {
        function initialize(&$controller) {
            $this->controller = $controller;
        }
    
        private function remote_connection_failed($data){
                $this->controller->set('data',$data); //your data
                $this->controller->__sendMail($from,$to,....);
        }
    

    or

    class RemoteComponent extends Object 
    {
        private function remote_connection_failed($data,$controller){
                $controller->set('data',$data); //your data
                $controller->__sendMail($from,$to,....);
        }
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid component that displays a few columns of data. It has
We have a classic ASP application that connects to a COM component. The COM
I have a component that I hand over a function public var func :
I have a component that is made up of various components such as a
I have a component that i want to store to an SQLite database. public
I have a component that has a sub-component they both use a shared variable
I have a visual component that I built from a TFrame (but then registered
Say I have a web component that uses jQuery and I want to distribute
I'd like to have a TabNavigator component that has a close button for some
I'm developing a XPCOM C++ component that have to use some RegExps functions Does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.