2013-03-28 5 views
1

안녕하세요, cakephp의 File :: write()에 이상한 문제가 있습니다.cakephp - 파일 저장 및 첨부 파일로 보내기

나는이 코드를 작성하여 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; 

} 

나는

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를 생성하고, 그래서이 내 코드는 attacchment로 보낼 필요 pdf는 폴더에 alredy입니다.

필자는 File :: write가 일종의 비동기 쓰기를 수행하고 시스템이 Email :: attachments 파일을 실행할 때 준비가되지 않았다고 생각합니다.

파일 가용성을 확인하기 위해이 코드에서 while()을 어떻게 삽입합니까?

감사합니다.

답변

1
if($file->write($viewdata)) 
{ 
    return $path; 
} 
0

반환 값을 사용하는 것만으로는 충분하지 않았습니다. 나를 위해 일을 시작하지 않고이 선

$file = new File($path, false); 

열기 파일을 변경했습니다.

관련 문제