【发布时间】:2011-11-06 21:56:36
【问题描述】:
出于几个不同的原因,我有一个连接到删除数据库的组件。然而,远程数据库不能保证正常运行,所以如果它出现故障,我想发送一封电子邮件提醒某人它失败了。
这是一个例子
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;
}
}
问题是组件类没有像控制器类那样的set() 方法。所以我得到这个错误:
致命错误:调用未定义的方法 RemoteComponent::set() in /var/www/app/controllers/components/remote.php 第 19 行
我需要为电子邮件将要使用的视图设置数据(不是呈现给用户的视图)
我想在组件内部处理这个问题,因为许多控制器可能出于不同的原因使用这个组件,这个组件处理与远程数据库的所有连接。
那么有什么想法最适合这种情况吗?
【问题讨论】:
标签: email cakephp components cakephp-1.3