Com o Gii criou-se o seguite:
controllers:
PostController.php (esse eu criei com este nome)
SiteController.php (já da configuração)
[b]
models:[/b]
Cep.php (esse eu criei)
ContactForm.php (conf original)
LoginForm.php (conf original)
views:
layout
–
–
–
post Esse post esta dentro da views(criou apos o Gii)
index.php
site
crudcep (eu criei)
Codigo de PostController.php
<?php
class PostController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
Codigo de Cep.php
<?php
/**
* This is the model class for table "Cep".
*
* The followings are the available columns in table 'Cep':
* @property string $Cep
* @property string $Estado
* @property string $Cidade
* @property string $Bairro
* @property string $Logradouro
* @property integer $Status
*/
class Cep extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Cep the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'Cep';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('Status', 'numerical', 'integerOnly'=>true),
array('Cep', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,
array('Estado', 'length', 'max'=>2),
array('Cidade, Bairro', 'length', 'max'=>100),
array('Logradouro', 'length', 'max'=>150),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('Cep, Estado, Cidade, Bairro, Logradouro, Status', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'Cep' => 'Cep',
'Estado' => 'Estado',
'Cidade' => 'Cidade',
'Bairro' => 'Bairro',
'Logradouro' => 'Logradouro',
'Status' => 'Status',
);
}
/**
* 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('Cep',$this->Cep,true);
$criteria->compare('Estado',$this->Estado,true);
$criteria->compare('Cidade',$this->Cidade,true);
$criteria->compare('Bairro',$this->Bairro,true);
$criteria->compare('Logradouro',$this->Logradouro,true);
$criteria->compare('Status',$this->Status);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
Código de Index.php
<?php
/* @var $this PostController */
$this->breadcrumbs=array(
'Cep',
);
?>
<h1><?php echo $this->id . '/' . $this->action->id; ?></h1>
<p>
You may change the content of this page by modifying
the file <tt><?php echo __FILE__; ?></tt>.
</p>
Código de crudcep.php
<?php
/* @var $this CepController */
/* @var $model Cep */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'cep-crudcep-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'Status'); ?>
<?php echo $form->textField($model,'Status'); ?>
<?php echo $form->error($model,'Status'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Cep'); ?>
<?php echo $form->textField($model,'Cep'); ?>
<?php echo $form->error($model,'Cep'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Estado'); ?>
<?php echo $form->textField($model,'Estado'); ?>
<?php echo $form->error($model,'Estado'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Cidade'); ?>
<?php echo $form->textField($model,'Cidade'); ?>
<?php echo $form->error($model,'Cidade'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Bairro'); ?>
<?php echo $form->textField($model,'Bairro'); ?>
<?php echo $form->error($model,'Bairro'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Logradouro'); ?>
<?php echo $form->textField($model,'Logradouro'); ?>
<?php echo $form->error($model,'Logradouro'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->