Best way to include TCPDF, PHPExcel and others

Hi,

I am new to yii 2.0 and don’t know what is the best way to include TCPDF an PHPExcel.

My Application is based on the basic template. In some views I will have an option to create PDF- and Excel-Output using the mentioned libs.

How can I import these libs, so that I can use them inside the relevant views? Maybe my problem is, that I do not really understand how to install or make an extension (I am not using composer).

Please can anybody give me a step by step instruction on how to get TCPDF running in the right Yii-Way?

You can use Yii import like given below

Yii::import(‘ext.phpexcel.Classes.PHPExcel’);

Th “right Yii-Way” is to use Composer. If you haven’t tried it yet, you should. One minute to set up, 15 minutes to learn the basics and it will make your life much easier.

Otherwise you are on your own, the framework itself can’t help you install, import or autoload 3rd party libraries. You have to follow the documentation of TCPDF and PHPExcel and install/include them as described there.

OK, I know I must learn to use composer. But TCPDF und PHPExcel aren’t Yii-extensions (or are there some available), will composer also help in installing a 3rd party lib?

Yes, it can install and autoload many 3rd party libraries, even your own libraries from a private repository.If a library doesn’t support Composer it’s probably outdated enough to avoid it.

Many thanks for your tips. Maybe this night I will find a litte bit of time for my first steps with composer. You convinced me that it is better to spent a little bit of time and save a lot afterwards :wink: