*/ | */ | ||||
public function sendEmail($email) | public function sendEmail($email) | ||||
{ | { | ||||
return Yii::$app->mailer->compose() | return Yii::$app->mailer->compose() | ||||
->setTo($email) | ->setTo($email) | ||||
->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes']) | ->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes']) |
namespace common\components ; | namespace common\components ; | ||||
class MyView extends \yii\web\View { | |||||
class MyView extends \yii\web\View | |||||
{ | |||||
var $title ; | var $title ; | ||||
var $page_title ; | var $page_title ; | ||||
public function setTitle($title, $page_title = '') { | |||||
public function setTitle($title, $page_title = '') | |||||
{ | |||||
$this->title = $title ; | $this->title = $title ; | ||||
if(strlen($page_title)) | if(strlen($page_title)) | ||||
$this->page_title = $page_title ; | $this->page_title = $page_title ; | ||||
$this->page_title = $title ; | $this->page_title = $title ; | ||||
} | } | ||||
public function getTitle() { | |||||
public function getTitle() | |||||
{ | |||||
return $this->title ; | return $this->title ; | ||||
} | } | ||||
public function setPageTitle($page_title) { | |||||
public function setPageTitle($page_title) | |||||
{ | |||||
$this->page_title = $page_title ; | $this->page_title = $page_title ; | ||||
} | } | ||||
public function getPageTitle() { | |||||
public function getPageTitle() | |||||
{ | |||||
return $this->page_title ; | return $this->page_title ; | ||||
} | } | ||||
public function getControllerAction() { | |||||
public function getControllerAction() | |||||
{ | |||||
return Yii::$app->controller->id.'/'.Yii::$app->controller->action->id ; | return Yii::$app->controller->id.'/'.Yii::$app->controller->action->id ; | ||||
} | } | ||||
namespace common\helpers; | namespace common\helpers; | ||||
class CSV { | |||||
class CSV | |||||
{ | |||||
public static function array2csv(array &$array) { | |||||
if (count($array) == 0) { | |||||
return null; | |||||
} | |||||
ob_start(); | |||||
$df = fopen("php://output", 'w'); | |||||
// clés | |||||
//fputcsv($df, array_keys(reset($array))); | |||||
foreach ($array as $row) { | |||||
fputcsv($df, $row); | |||||
} | |||||
fclose($df); | |||||
return ob_get_clean(); | |||||
} | |||||
public static function downloadSendHeaders($filename) { | |||||
// disable caching | |||||
$now = gmdate("D, d M Y H:i:s"); | |||||
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); | |||||
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); | |||||
header("Last-Modified: {$now} GMT"); | |||||
// force download | |||||
header("Content-Type: application/force-download"); | |||||
header("Content-Type: application/octet-stream"); | |||||
header("Content-Type: application/download"); | |||||
// disposition / encoding on response body | |||||
header("Content-Disposition: attachment;filename={$filename}"); | |||||
header("Content-Transfer-Encoding: binary"); | |||||
} | |||||
/* | |||||
* usage | |||||
* download_send_headers("data_export_" . date("Y-m-d") . ".csv"); | |||||
echo array2csv($array); | |||||
die(); | |||||
*/ | |||||
public static function array2csv(array &$array) | |||||
{ | |||||
if (count($array) == 0) { | |||||
return null; | |||||
} | |||||
ob_start(); | |||||
$df = fopen("php://output", 'w'); | |||||
// clés | |||||
//fputcsv($df, array_keys(reset($array))); | |||||
foreach ($array as $row) { | |||||
fputcsv($df, $row); | |||||
} | |||||
fclose($df); | |||||
return ob_get_clean(); | |||||
} | |||||
public static function downloadSendHeaders($filename) | |||||
{ | |||||
// disable caching | |||||
$now = gmdate("D, d M Y H:i:s"); | |||||
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); | |||||
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); | |||||
header("Last-Modified: {$now} GMT"); | |||||
// force download | |||||
header("Content-Type: application/force-download"); | |||||
header("Content-Type: application/octet-stream"); | |||||
header("Content-Type: application/download"); | |||||
// disposition / encoding on response body | |||||
header("Content-Disposition: attachment;filename={$filename}"); | |||||
header("Content-Transfer-Encoding: binary"); | |||||
} | |||||
/* | |||||
* usage | |||||
* download_send_headers("data_export_" . date("Y-m-d") . ".csv"); | |||||
echo array2csv($array); | |||||
die(); | |||||
*/ | |||||
} | } |
use Yii; | use Yii; | ||||
class Mail { | |||||
public static function send($email, $subject, $view, $data) { | |||||
class Mail | |||||
{ | |||||
public static function send($email, $subject, $view, $data) | |||||
{ | |||||
$mail = Yii::$app->mailer->compose( | $mail = Yii::$app->mailer->compose( | ||||
[ 'html' => $view.'-html', | [ 'html' => $view.'-html', | ||||
'text' => $view.'-text' | 'text' => $view.'-text' |
class Price { | class Price { | ||||
public static function format($number) { | |||||
public static function format($number) | |||||
{ | |||||
return number_format($number, 2).' €' ; | return number_format($number, 2).' €' ; | ||||
} | } | ||||
use yii\web\UploadedFile; | use yii\web\UploadedFile; | ||||
use Yii ; | use Yii ; | ||||
class Upload { | |||||
class Upload | |||||
{ | |||||
public static function uploadFile($model, $champs, $filename_old = '') { | |||||
public static function uploadFile($model, $champs, $filename_old = '') | |||||
{ | |||||
$file = UploadedFile::getInstance($model, $champs); | $file = UploadedFile::getInstance($model, $champs); | ||||
if ($file) { | if ($file) { | ||||
$file_name = $file->baseName . '-' . uniqid() ; | $file_name = $file->baseName . '-' . uniqid() ; |
} | } | ||||
} | } | ||||
public static function slugify($string) { | |||||
public static function slugify($string) | |||||
{ | |||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))); | return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))); | ||||
} | } | ||||
} | } |