1.1.1 new crud generation

Hi all,

according to the upgrade instructions:

I have quite a big application and would like to implement the new filter and the search part of the crud. The advice is to regenerate the webapp. I simply cannot afford another month to rewrite all my application so my question is:

What issue appears when we crud on the old app[1.1]. Is there a work around [switching code here and there] without rewriting everyting and what is it?




I have a ton of models that have been customized as well as lots of changes to controllers and views so I’m in the same boat. But I’m starting the upgrade… :wacko:

Anyways I just created a new site and I’m copying over all old stuff while looking what’s new and I created one to see what’s new:

  1. In the Controller (crud created) it looks like there’s an added function:


 * Performs the AJAX validation.

 * @param CModel the model to be validated


protected function performAjaxValidation($model)


    if(isset($_POST['ajax']) && $_POST['ajax']==='project-form')


        echo CActiveForm::validate($model);




It also adds this line (commented out) in the Update and Create functions:

// Uncomment the following line if AJAX validation is needed

// $this->performAjaxValidation($model);

  1. Adds an extra array on the rules function in the model:

public function rules()


    return array(


        // The following rule is used by search().

        // Please remove those attributes that should not be searched.

        array('id, name', 'safe', 'on'=>'search'),


And also adds a search function:


 * Retrieves a list of models based on the current search/filter conditions.

 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


public function search()


    // Warning: Please modify the following code to remove attributes that

    // should not be searched.

    $criteria=new CDbCriteria;




    return new CActiveDataProvider('Project', array(




  1. The view "_search.php" has been added by the crud:

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

    <div class="row">

        <?php echo $form->label($model,'id'); ?>

        <?php echo $form->textField($model,'id'); ?>


    <div class="row">

        <?php echo $form->label($model,'name'); ?>

        <?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>


    <div class="row buttons">

        <?php echo CHtml::submitButton('Search'); ?>


<?php $this->endWidget(); ?>

</div><!-- search-form -->

  1. The admin view has quite a few changes for ajax search and filter:







    array('label'=>'List Project', 'url'=>array('index')),

    array('label'=>'Create Project', 'url'=>array('create')),


Yii::app()->clientScript->registerScript('search', "



    return false;


$('.search-form form').submit(function(){

    $.fn.yiiGridView.update('project-grid', {

        data: $(this).serialize()


    return false;




<h1>Manage Projects</h1>


You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(


)); ?>

</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(











)); ?>

  1. The _form view also has a few changes (for ajaxValidation):

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

... rest is the same

I think that’s pretty much it. I should note that if you link to the yii-1.1.1 without recreating your site you will get an error in the yiic tool.

EDIT: The steps I’d take are:

  1. Create a new site (different name or rename the old).

  2. Copy over all the old stuff that you’ve changed (css, js, config, models, controllers, views, etc.)

  3. Create a new model with the new crud and copy paste any new stuff you want into old models.

woow nice comment lgoss007. thanks for sharing mate. I am taking your way to upgrade my website. if you hit into anything interesting or anything warning please share.

Cheers mate,


There are also some CSS changes in main.css & form.css.

Also new Controller.php file in components folder and some new layouts in views/layouts (you will need to modify your existing main.php layout file to make use of these new layout files).

Cheers mate. do you know if the layouts are automatically populated by yiic or I have to edit every controller to apply the layouts/

Thanks GSTAR



If you want to keep everything as it was in 1.1.0, just ensure in components/controller.php you have:

public $layout=‘application.views.layouts.column1’;

Any new controllers created by the crud command will use column2 layout by default.

Hi @all

thanks Igoss007 !

other change

in LoginForm function authenticate

the condition "case UserIdentity::ERROR_NONE:" is not anymore

and there is a new method

public function login()


in the SiteController public function actionLogin()




if($form->validate() && $form->login())


Hello @gstar,

I Already change it to layout.column1 but after Crud operation, its always use Layout.column2 … how to change the default layout?