How to add a new column with Yii2 migration on a specific table

category:  Yii2.0 framework

Today I want to add a new column into the existing table in Yii2. Instead of adding the new column via the model I prefer to add the new column via the Yii2 migration script. With a script, I can easily revert the scrip in the command line. In order to work with the migration script, we will use the command line via the terminal. I use the bash terminal via VScode. You can use any terminal as you prefer. … Read More

Add new font into yii2-mpdf extension

category:  Yii2.0 framework

In the Yii2 framework, you want to print or export the data as a PDF file. One of popular extension is yii2-mpdf. The extension uses an mPdf library. The extension is easy to use and the document is provided. However, if you want to add a new custom font in order to use in the Pdf file, no document in yii2-mpdf extension is provided. You have to look at the document of the mPdf library instead. For an experienced web … Read More

How to set the application timezone and MySQL for Yii2

category:  Yii2.0 framework

I built my own application in 2017 when I lived in the USA and all my clients were American. The timezone that I set at that time is Pacific timezone. In 2018, I moved back to Thailand and I need to set a new timezone. I will share how to set the timezone in MySQL and PHP in the Yii2 application. My host is a shared host so if you have the dedicated host it will work as well. Set … Read More

How to clear the assets cache in Yii2

category:  Yii2.0 framework

With Yii2, it comes with the asset management calls asset bundle. An asset bundle is simply a collection of assets located in a directory. When you register an asset bundle in a view, it will include the CSS and JavaScript files in the bundle in the rendered Web page. Below is my asset bundle setting in my application. I use the advanced template from Yii2 and I use the frontend for my application(backend, console, and frontend folders are generated from the advanced … Read More

How to save the multi-records in one model in a single transaction in Yii2

category:  Yii2.0 framework

Recently I just add the new feature on my application. What new feature does, it generates the new invoice from the time-sheet. This way, my clients can see my log time and note on each task. So they know in detail what I did for their project. The steps are: get the time-sheet data filtered by the specific client, date range and unbilled status In the time-sheet loop, insert the new invoice and invoice detail If something goes wrong while … Read More

How to export database from Yii2 application

category:  Yii2.0 framework

The export database feature is nice to have for backup and restore the database from either website or web application. I added the export database in my application using the PHP based MySQL dump library. I did the search and found more two ways to achieve my goal but they have the issue with the null value and text data type. One of the two ways is to generate the insert script with PHP which can not generate the insert script … Read More

How to create the bulk action in Yii2

category:  Yii2.0 framework

Howdy, working in the back-end in the web application, often you will find the bulk actions is very useful when you want to do the action with more than one record at once. Today I will share with you how to create bulk actions and work with grid view widget. Plus I use the pjax widget to make the changes from the action without reloading the whole page. The screenshot below shows the bulk action in Yii2 Here is what … Read More

How to create the module in Yii2

category:  Yii2.0 framework

Recently I have been adding the new features to my own application. I add new features using the module so I can disable and enable each module easily in the application configuration. The module is a self-contained software unit that contains models, controllers and views and components. I prefer to use Gii module to create the new module. I set up my application with the advanced template and I build my application in the frontend root. Gii module URL(with enabling … Read More

How to remove the extension or package with composer

category:  Yii2.0 framework

Often when I work with the PHP framework and I want to install the extensions or packages in general term, in order to use in the framework, for PHP, we use composer. In js framework, you will use npm or yarn. To install the extensions, the third party(extension owner) page will let you know the installation composer command. But often they don’t provide you how to remove or uninstall the extensions. I will share this with you today. When the … Read More

How to add the pagination dropdown list in GridView in Yii2

category:  Yii2.0 framework

Earlier, I wrote how to add the summary footer in the gridview widget. The grand total column will sum all the total columns on each page and the default page size of gridview is 20 items per page. I want to be able to change the page size as I want in order to see the new grand total if I choose the search filter. Below is the screenshot that I did. We will add the extra code in two … Read More