Sometimes while getting value from foreign key relation, dependency is more than one level. This post covers how to get value from base table and enable search in gridview.

Consider following scenario:

User table: Userid, transaction_id,user_type

Transaction : Userid, info_id

Info : info_id, name

Suppose requirement is to show name of user in user grid. Here , to relate name and userid , there is a 2 level dependency through transaction table.

Here we are not taking name field directly in user table, because, there are different type of user and each type has different info table which contains name.Transaction table is a master table for each type which has ids like user_id,info_id, address_id etc.

To create yii application, command is ./yiic/webapp app-name.
Application is generated under framework folder and it is as per default yii defined structure.
This guide is to customize the structure of default Yii application generation.

The default webapplication created is copy of yii/framework/cli/views/webapp.
To customize it, one can change it directly, but it is not recommended way.
We should make a copy of it and save as different name like mywebapp.
New copy should be in same folder yii/framework/cli/views.
Make all changes as per your file structure and change in code, add components,theme for your application in it.

Open webappcommand.php file from yii/frameworkcli/commands.
We need to change SourceDir name to our new name.Change following line in code
$sourceDir=realpath(dirname(__FILE__).’/../views/webapp’);
to
$sourceDir=realpath(dirname(__FILE__).’/../views/mywebapp’);

Now our new yii web application structure is ready.
Run ./yiic webapp app-name,& It will make a application as per your changes.
You can generate application yii default or customize by changing source directory in webappcommand.php file.
Start customizing it!!!
All the best!!!
Have a good day!!!

Yii framework offers default crud generation feature. If you write your application name/gii, it will show default crud generation operations. Many times we use different template in project than default crud and need to made changes after watch time crud is generated. This is post to customize default crud to get rid of redundant task.
Let’s begin.

When you are writing in your application-name/gii ,you are seeing all generators on index.
This generator code is located at yii/framework/gii/views/index.php
Here ,each generator link related code located at yii/framework/gii/generators,
We will extend basic crud and do change in it, so we are able to generate default crud in other applications.

2.Make generator in giiextended folder,like MyCrudGenerator, which extends CrudGenerator.
You need to change in $codeModel ,which give path to code file,
here myCode.
Import : Yii::import(‘gii.generators.crud.CrudGenerator’);
$codemodel=giiextended.myCrud.myCrudCode.
Also make it in mycrud,where $codemodel=ext.giiextended.myCrud.myCrudCode
please notice that,if folder name is mycrud,generate will be name of MycrudGenerator,first letter will be capital.

3.Make Folder template in mycrud folder,in which all views and controller in default folder.Here what you will make changes accordingly future views are generated from your crud.Following views need to be generated as per Yii crud, you can skip 1 or 2 views and change it as per your need, but you need to reflect changes in controller accordingly.

_form.php

_search.php

_view.php

admin.php

controller.php

create.php

update.php

index.php

view.php

4.Make a folder view,put a index.php in it,
copy it form crud(framework/gii/generators/crud/view/index.php) ,change name in h1 tag.

5.In config/main.php,in gii in generatorpath array,add ext.giiextended.
as example:
‘generatorPaths’=>array(
//’ext.gii-extended’,
),
This will responsible for showing uour customized crud name when you type application-name/gii in url. So try it and you will come out of hustle of each time crud change as new table is generated.
Similaraly,you are able to extend model and form generator also of gii.
Start doing it.All the Best!!!
Have a good day!!!

Welcome to WordPress.com! This is your very first post. Click the Edit link to modify or delete it, or start a new post. If you like, use this post to tell readers why you started this blog and what you plan to do with it.