Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers;
- use app\models\Document;
- use Imagick;
- use Spatie\PdfToImage\Pdf;
- use Yii;
- use yii\filters\AccessControl;
- use yii\helpers\Url;
- use yii\web\UploadedFile;
- class DocumentController extends AbstractController
- {
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- public function actionUpdate($id = null)
- {
- if ($id) {
- $model = $this->findModel($id, Document::className());
- } else {
- $model = new Document;
- }
- if ($post = Yii::$app->request->post()) {
- if ($model->load($post) && $model->save()) {
- $this->notice('Your changes have been saved successfully.');
- } else {
- $this->notice($model->errors, 'error');
- }
- return $this->redirect(['site/dashboard']);
- }
- return $this->render('update', [
- 'model' => $model,
- 'id' => $id,
- ]);
- }
- public function actionSave()
- {
- if ($id = Yii::$app->request->post('document_id')) {
- $model = $this->findModel($id, Document::className());
- } else {
- $model = new Document;
- }
- $model->updated_at = time();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(Url::to(['site/dashboard']));
- }
- return 'failed!';
- }
- public function actionGeneratePdf($id)
- {
- $model = Document::findOne(['id' => $id]);
- $pdf = Yii::$app->pdf;
- $pdf->content = $this->renderPartial('document', ['model'=>$model]);
- $pdf->cssInline = '
- .title-page {
- padding-top:50%;
- text-align:center;
- height:100%;
- }
- .title {
- padding: 10px 0 10px 0;
- border-top: 1px solid black;
- border-bottom: 1px solid black;
- font-size: 20px;
- font-weight: bold;
- }
- ';
- $pdf->execute('SetHeader', $this->renderPartial('parts/header'));
- return $pdf->render();
- }
- public function actionDelete(array $id)
- {
- return $this->delete(Document::className(), $id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement