Category Archives: Yii Framework 2.0

Yii Framework 2 : Cookies Handling

A cookie is a small file that the server embeds on the user’s computer and it is often used to identify a user. In plain PHP we can access using $_COOKIE global variable. In Yii, cookie is an object of ‘yii\web\Cookie’. ‘yii\web\Request’ and ‘yii\web\Response’ maintain a collection of cookies via the property named cookies. Set […]

Yii Framework 2 : Create PDF Files Using mPDF

mPDF is a PHP class Which is used to create a PDF files from the HTML content in yii2.0. Install mPDF Create PDF Using mPDF Install mPDF Install mPDF Using Composer To include the mPDF package into yii2.0 application folder, add the following code into ‘composer.json’ file and run the command ‘composer update’. Now you […]

Yii Framework 2 : Custom Pagination

When we are having more data and have to split it as many pages using pagination. By default, Yii2.0 is having that option for pagination. For the pagination, we have to send some information to page they are total item count, page size(number of records per page), current page etc. Simple Pagination CustomPagination Class Custom […]

Yii Framework 2 : Delete Query

Model delete() delete() With Condition delete() With Query delete() With Prepared Statements find() And Delete() deleteAll() Model delete() $model = User::find($id); $model->delete(); delete() With Condition $connection->createCommand() ->delete(‘tbl_user’, ‘status = 0’) ->execute(); delete() With Query $connection->createCommand(‘DELETE FROM tbl_user WHERE userid=:userid’) ->execute(); delete() With Prepared Statements Sample 1: $model = $connection->createCommand(‘DELETE FROM tbl_user WHERE userid=:userid’); $model->bindParam(‘:userid’, $userid); […]

Yii Framework 2 : Gridview

In yiiframework 2.0, The gridview widget is used to display the data like image, text, etc in a grid. It is having a lot features like sorting, pagination, filtering, styling etc. This widgets is mostly used by developers. I added some properties for this Sample Category GridView Gridview Options Table Options Table Row Options Gridview […]

Yii Framework 2 : GridView To Excel Export Extension

Are you struggling for exporting data to excel? This tutorial will helpful to create your own extension for exporting data as excel from your gridview data. What you display in gridview (text), It will export as excel. Install PHP Excel Excel Gridview Class Gridview To Excel Install PHP Excel In Yiiframework 2.0 Add below line […]

Yii Framework 2 : Create Custom Component

Yii2.0 framework having default application components and it is giving different type services. For example ‘urlManager’ component, ‘db’ component etc. Every application component has an uniqueID and will call through expression format. We can create Application components like global or local variables. Syntax And Core Components Create Your Own Component Config Component Call Yii Custom […]

Yii Framework 2 : Create Custom Widget

This tutorial will help you to create your own custom widget in yii framework 2.0. Widgets are reusable blocks and it is used in view. To create a widget, Extend from yii\base\Widget. Override the yii\base\Widget::init() and/or yii\base\Widget::run() methods. Note: In yii 1.x, we will use component folder. Create Your Own Widget Display Your Widget Content […]

Yii Framework 2 : Insert Query

save() OR insert() insert() command batchInsert() save() OR insert() $model = new User; $model->name = ‘YII’; $model->email = ‘[email protected]’; $model->save(); // equivalent to $model->insert(); insert() command $connection->createCommand()->insert(‘tbl_user’, [ ‘name’ => ‘yii’, ‘status’ => 1, ]) ->execute(); batchInsert() Insert multiple rows at once using batchInsert() function. $connection->createCommand()->batchInsert(‘tbl_user’, [‘name’, ‘status’], [ [‘Bala’, 1], [‘Akilan’, 0], [‘Babu’, 1], […]

Yii Framework 2 : Install New Theme

Install Theme Configuration Of Theme Sample theme layout Themes is very important to make cool our application. In yiiframework 2.0, we are having lot of new features in theming compare to yiiframework 1.0 like We can override the the active theme. Install Theme First we have to install the theme in yiiframework2.0.Please follow the below […]