I am still new to composer and packagist, so I want to share how I am creating the pdf files because for me was not as simple as it should be.
First of all we will intall mpdf with composer :
php composer.phar require mpdf/mpdf "dev-master"
Now, in a controller we will call / use / import the library. In this case for testing purpose we will use the SiteController controller.
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
#We will include the pdf library installed by composer
use mPDF;
class SiteController extends Controller {
Now, lets create and action for testing our library.
public function actionPdf() {
$mpdf = new mPDF;
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output();
exit;
}
Now if we access our action through a website we should have a pdf as the following :
Hope that this works for you :)
Good job
Hi, thank you for sharing it; good job !
Real example from active record
Thank you for the package
Would you please provide a real example from active record.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.