你有一個奇怪的問題,在cakephp中的File :: write()。cakephp - 保存文件syncronized並作爲附件發送
我寫這段代碼來生成pdf視圖並將其保存在文件中。
private function generate($id){
$order = $this->Order->read(null, $id);
$this->set('order', $order);
$view = new View($this);
$viewdata = $view->render('pdf');
//set the file name to save the View's output
$path = WWW_ROOT . 'ordini/' . $id . '.pdf';
$file = new File($path, true);
//write the content to the file
$file->write($viewdata);
//return the path
return $path;
}
我需要生成PDF這並把它作爲attacchment這樣,這是我的代碼
public function publish ($id) {
$pdf_file = $this->generate((int)$id);
$Email = new CakeEmail();
$Email->from(array('[email protected]' => '......'));
$Email->to('[email protected]');
$Email->subject('Nuovo ordine');
$filepath = WWW_ROOT . 'ordini/' . $id . '.pdf';
$Email->attachments(array('Ordine.pdf' => $filepath));
$Email->send('......');
}
我第一次運行該代碼的電子郵件不工作,電子郵件的工作不錯,如果只PDF文件在文件夾中。
我認爲,文件::寫執行某種異步寫的,當系統運行電子郵件附件::文件ins't準備。
我該如何在此代碼中插入while()以檢查文件可用性?
非常感謝。