INFRA

cakePHP2.3 フォルダの作成など

フォルダとかファイルとかをいじりたいときは、

App::uses('Folder', 'Utility');
App::uses('File', 'Utility');

を設定する。

以下の関数内でフォルダをあるかないか確認したり、消したり、作ったりした。 でも、$dir->create(‘フォルダ名’);とやると、webroot以下だと作れたが、それより上位層だと作れなかった。。。 なんでだろう。これではまったので、細かいことを調べていないがとりあえずメモ。

private function make_bill($filename,$info){
Configure::write('debug', 0);
App::import('Vendor', 'Mpdf/mpdf');
//PDF作成用HTMLの取得
$View = new View();
$View->viewPath = 'Jobs'; // Viewの下のフォルダ名
$View->viewVars = $info; //パラメータ
$html = $View->render('make_bill','pdf');
//保存先パスの作成
$path = $this->bill_path;
$path .= $info['job_id'];
//ディレクトリ・ファイルの存在チェック
//job_idのフォルダがあったら1回消して再度つくる
//なかったらつくる
$dir = new Folder($path);
if($dir){
$dir->delete();
$dir = new Folder($path,true,0755);
}else{
$dir = new Folder($path,true,0755);
}
if($dir){
$path = $dir->path . DS;
//PDF作成
$mpdf = new mPDF('ja', 'A4');
$mpdf->writeHTML($html);
$mpdf->Output($path . $filename,'F');
return true;
}else{
return false;
}
}