mpdf export chinese character

mpdf export chinese char:
vendor/mpdf/mpdf/config.php, change below two line to true, for v6

$this->autoScriptToLang = true;
$this->autoLangToFont = true;

autoScriptToLang is variable to indicate whether add below inline style to
no-ascii char in html source;

<span lang="und-Hans" class="lang_und-Hans">由</span>Yii2 Grid<span lang="und-Hans" class="lang_und-
 Hans">导出的</span>

autoLangToFont is a variable to indicate whether to choose font with
upper’s inline style’s data;

for chinese:
useAdobeCJK is true: font is gb/big5. it will use adobe’s cjk font
useAdobeCJK is false: font will be Sun-ExtA.ttf

usingCoreFont : if there exist font-family style in html content, mpdf
will try to resolve it to it’s inner font, if this process is success, the set
this variable to true;

v5 maybe need change:

$this->useAdobeCJK = true;

mpdf’s font issue, can only set font to mpdf’s font, if you want to user
system font, you should change it’s code

some method in PHP

php
is_null:
use === intstead of is_null
isset($var) and is_null($var) 是相反的;is_null只有在变量是NULL或者变量声明了但是没有赋值时返回true
is_callable :
if the application could call a method on the object, from the current scope,
then use is_callable
method_exists :
only check this method exist in specified class or not, it will not check it
can run from current scope

debug codeception in Eclipse

  1. config eclipse’s php cli’s debug to using xdebug
  2. copy file to codeception
cp vendor\codeception\codeception\codecept to vendor\codeception\codeception\codecept.php

then add this file to eclipse’s cli run configuration, then add script
argument as below:

run -c D:\git\yii2\basic\vendor\arogachev\yii2-excel\codeception.yml

then debug, the yii2-excel’s ut will be debuggable

Yii2 UT

run below command to instanll codeception:

composer require "codeception/codeception=2.1.*"
composer require "codeception/specify=*"
composer require "codeception/verify=*"

add project/vendor/bin to you PATH

cd to you ut directory; codeception build; codeception run

how to solve git detached HEAD

how to solve git detached HEAD
1. checkout to other branch
2. or create a new branch with : git checkout -b branch_name
3. or prevent to use git checkout commit_id, this will cause detached HEAD
status

Change Yii2 language

you can using request header/cookie to change Yii’s language dynamic or using
below code:

// change target language to Chinese
\Yii::$app->language = 'zh-CN';