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…
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:
- 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);
Yii::app()->end();
}
}
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);
- 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;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
return new CActiveDataProvider('Project', array(
'criteria'=>$criteria,
));
}
- The view "_search.php" has been added by the crud:
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<div class="row">
<?php echo $form->label($model,'id'); ?>
<?php echo $form->textField($model,'id'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
- The admin view has quite a few changes for ajax search and filter:
<?php
$this->breadcrumbs=array(
'Projects'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Project', 'url'=>array('index')),
array('label'=>'Create Project', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('project-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Projects</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'project-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
- The _form view also has a few changes (for ajaxValidation):
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'project-form',
'enableAjaxValidation'=>false,
)); ?>
... 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:
-
Create a new site (different name or rename the old).
-
Copy over all the old stuff that you’ve changed (css, js, config, models, controllers, views, etc.)
-
Create a new model with the new crud and copy paste any new stuff you want into old models.