Difference between #22 and #23 of
Yii v2 snippet guide II

Revision #23 has been created by rackycz on Sep 8, 2020, 7:58:29 PM with the memo:

Composer and PhpExcel
« previous (#22) next (#24) »

Changes

Title unchanged

Yii v2 snippet guide II

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2,snippets

Content changed

[...]
**Creating models in Gii for remote MSSQL tables**
---
Once you have added the 2nd database (read above) go to the Model Generator in Gii. Change there the DB connection to whatever you named the connection in yii-config (in the example above it was "db2") and set tablename in format: SCHEMA.TBL_NAME. If MSSQL server has more databases, one of them is set to be the main DB. This will be used I think. I haven't succeeded to change the DB. DB can be set in the DSN string, but it had no effect in my case.

**
Using composer-packages - for example PhpExcel/PhpSpreadsheet in Yii 2PhpExcel/PhpSpreadsheet in Yii 2 and sending binary content to the browser**
---
In previous chapters I showed how to use [PhpExcel in Yii 1](https://www.yiiframework.com/wiki/462/yii-for-beginners-2). Now I needed it also in Yii 2 and it was extremely easy.
[...]
]);
```

 
This also worked for me:
 
 
```php
 
$tmpFileName = uniqid('file_').'.xlsx';
 
$writer->save($tmpFileName);    
 
header('Content-Type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
 
header('Content-Disposition: attachment;filename="filename.xlsx"');
 
header('Cache-Control: max-age=0');
 
echo file_get_contents($tmpFileName);
 
unlink($tmpFileName);
 
exit();
 
```
 
4 0
3 followers
Viewed: 75 533 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Aug 26, 2020
Last updated: 3 years ago
Update Article

Revisions

View all history